0
votes

I'm getting the following (and many more) errors when attempting to link my project statically with boost.log on MSVC 10.0:

 1>libboost_log-vc100-mt-gd-1_53.lib(attribute_name.obj) : error
 LNK2001: unresolved external symbol "**__declspec(dllimport)** public:
 __thiscall std::_Container_base::~_Container_base(void)" (__imp_??1_Container_base@std@@QAE@XZ)
 1>libboost_log-vc100-mt-gd-1_53.lib(text_file_backend.obj) : error
 LNK2001: unresolved external symbol "**__declspec(dllimport)** public:
 __thiscall std::_Container_base::~_Container_base(void)" (__imp_??1_Container_base@std@@QAE@XZ)

Note that the project is linking also to boost system, filesystem, and thread libraries.

1>      Searching ../lib/\libboost_system-vc100-mt-gd-1_53.lib:
1>      Searching ../lib/\libboost_date_time-vc100-mt-gd-1_53.lib:
1>      Searching ../lib/\libboost_regex-vc100-mt-gd-1_53.lib:
1>      Searching ../lib/\libboost_thread-vc100-mt-gd-1_53.lib:
1>      Searching ../lib/\libboost_chrono-vc100-mt-gd-1_53.lib:
1>      Searching ../lib/\libboost_log-vc100-mt-gd-1_53.lib:
1>      Searching ../lib/\libboost_filesystem-vc100-mt-gd-1_53.lib:

My project does not define the BOOST_ALL_DYN_LINK or BOOST_LOG_DYN_LINK macros, so I was not expecting to see the __declspec signatures, which I am thinking is the ultimate problem. Am I missing something required to properly link this library statically?

Update

I removed precompiled headers on my project and performed a "clean", and everything linked fine. Is it possible that precompiled headers were somehow causing the project to link statically to CRT?

1
BOOST_ALL_DYN_LINK forces Boost libraries to link dynamically, while __declspec signatures you see are related to the standard c++ library, which is linked dynamically. PCH couldn't alter CRT linkage, it's only MT/MD compiler option, but there usually exist some glitches in IDEs, so it's always good to clean & rebuild.Igor R.
@IgorR. Always something to learn. Thanks for your help, feel free to re-post as answer.jwalk
I think it doesn't answer your question, because I have no idea what was wrong with your project settings.Igor R.

1 Answers

0
votes

You may need link log_setup firstly and then log before filesystem and so on, this was boost link code in my CMakeLists.txt:

set(USED_BOOST_LIBS ${Boost_LOG_SETUP_LIBRARY} ${Boost_LOG_LIBRARY} 
  ${Boost_FILESYSTEM_LIBRARY} 
  ${Boost_SYSTEM_LIBRARY} ${Boost_DATE_TIME_LIBRARY} 
  ${Boost_THREAD_LIBRARY} ${Boost_REGEX_LIBRARY} 
  )

...
target_link_libraries(myexe ${USED_BOOST_LIBS})

It works fine with me both on MSVC 14.0 and gcc 4.8.You can try it.