3

I have a project that has some main.cpp and the following precompile header:

 <!-- language: lang-cpp -->
 #ifndef PRECOMPILE_H
 #define PRECOMPILE_H
 #include <iostream>
 #include <string>
 #include <vector>
 #include <boost\asio.hpp>
 #include <boost\bind.hpp>
 #include <boost\asio\ssl.hpp>
 #include <boost\locale.hpp>
 #include <boost\algorithm\string.hpp>
 #endif 

If the project is *.lib, it always builds normally.

If project the is *.exe:
When build with Create (/Yc), all ok.
When setting Use (/Yu) I get linker error LNK2001:

1) unresolved external symbol "private: static class boost::asio::detail::tss_ptr::context> boost::asio::detail::call_stack::top_" (?top_@?$call_stack@Vstrand_impl@strand_service@detail@asio@boost@@E@detail@asio@boost@@0V?$tss_ptr@Vcontext@?$call_stack@Vstrand_impl@strand_service@detail@asio@boost@@E@detail@asio@boost@@@234@A)

2) unresolved external symbol "public: static class boost::asio::detail::service_id boost::asio::detail::service_base::id" (?id@?$service_base@Vselect_reactor@detail@asio@boost@@@detail@asio@boost@@2V?$service_id@Vselect_reactor@detail@asio@boost@@@234@A)

3) unresolved external symbol "public: static class boost::asio::detail::service_id boost::asio::detail::service_base::id" (?id@?$service_base@Vstrand_service@detail@asio@boost@@@detail@asio@boost@@2V?$service_id@Vstrand_service@detail@asio@boost@@@234@A)

4) unresolved external symbol "public: static class boost::asio::detail::service_id > > boost::asio::detail::service_base > >::id" (?id@?$service_base@V?$deadline_timer_service@Vptime@posix_time@boost@@U?$time_traits@Vptime@posix_time@boost@@@asio@3@@asio@boost@@@detail@asio@boost@@2V?$service_id@V?$deadline_timer_service@Vptime@posix_time@boost@@U?$time_traits@Vptime@posix_time@boost@@@asio@3@@asio@boost@@@234@A)

Boost: v1_49 static /MTd

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
DeadWarlock
  • 720
  • 6
  • 23
  • How exactly are you using PCH here? You need to link in the `/Yc` object file that is output from the precompiled header build, with the rest of the object files (the ones built using `/Yu`). See here for a similar question: http://stackoverflow.com/questions/998881/scons-boostasio-windows-precompiled-headers-and-linker-errors – Steve Townsend May 21 '12 at 14:59
  • I do not understand which object must link to other objects. For clarify: when delete all places where using `asio` library (_from source and precompile header_) and add something other from boost in precompile header (for example: `boost::bind`) all works fine. If you look to the error - we have only asio errors other include files visual studio see and work fine. – DeadWarlock May 21 '12 at 16:00
  • 1
    If your precompiled header is called `PCH.H` you also should have a `PCH.CPP` file that gets compiled with `/Yc` and linked (as `PCH.OBJ`) to all the others that you compile with `/Yu`. – Steve Townsend May 21 '12 at 16:05
  • Thank you very much Steve Townsend it is works. You open my eyes and save my life. Now i do not understand why it works in other cases. – DeadWarlock May 22 '12 at 07:24
  • OK, I've added this as an answer for future reference. Glad to hear it's sorted out now. – Steve Townsend May 22 '12 at 10:51

1 Answers1

3

If your precompiled header is called PCH.H you also should have a PCH.CPP file that gets compiled with /Yc and linked (as PCH.OBJ) to all the others that you compile with /Yu.

For the other cases that work, perhaps this is because nothing static from the Boost headers has to get exported from the precompiled header object file.

Steve Townsend
  • 53,498
  • 9
  • 91
  • 140