10
votes

I'm using boost in my project. I've downloaded pre-compiled binaries from here http://boost.teeks99.com/

When linking I receive such error:

Error 18 error LNK2005: "public: void __cdecl boost::thread::join(void)" (?join@thread@boost@@QEAAXXZ) already defined in boost_thread-vc110-mt-1_52.lib(boost_thread-vc110-mt-1_52.dll) C:\Oleg\projects\MBClient\FastNativeAdapter\libboost_thread-vc110-mt-1_52.lib(thread.obj) FastNativeAdapter

Why boost contains two lib with so similar name, what is the difference between them?

  • libboost_thread-vc110-mt-1_52.lib
  • boost_thread-vc110-mt-1_52.lib

How to fix linking error?

upd I've compiled boost myself. I've added boost_1_53_0\stage\lib directory to linker. This directory actually contains 3 "copies" of "each" file, for example:

  • boost_atomic-vc110-mt-1_53.dll
  • boost_atomic-vc110-mt-1_53.lib
  • libboost_atomic-vc110-mt-1_53.lib

So It's clear what compiler claims about. Somehow it can't understand which version of lib file to use. It's likely connected with static/dinamic linking, but I still can not find the solution. I'm sure my problems is pretty common so I hope someone can suggest me what to do.

I've tried to delete all "libboost*" files from folder but then I receive such error: Error 15 error LNK1104: cannot open file 'libboost_date_time-vc110-mt-1_53.lib'

I've tried to delete all "boost*lib" files from folder but then I receive such error: Error 15 error LNK1104: cannot open file 'boost_thread-vc110-mt-1_53.lib'

Then I copied boost_thread-vc110-mt-1_53.lib back and I receive a lot of errors like that:

Error 16 error LNK2005: "public: virtual __cdecl boost::detail::thread_data_base::~thread_data_base(void)" (??1thread_data_base@detail@boost@@UEAA@XZ) already defined in boost_thread-vc110-mt-1_53.lib(boost_thread-vc110-mt-1_53.dll)

So when there are no boost_thread-vc110-mt-1_53.lib compiler claims that it's missing, when there is boost_thread-vc110-mt-1_53.lib compiler claims that "function is already defined". Probaly somehow I do use dinamic and static linking at the same time or something like that?

upd2 i've uncommented #define BOOST_ALL_DYN_LINK as suggested here and now code compiles! i'm investigating if everything else is fine. however i didn't understand why I should uncomment #define BOOST_ALL_DYN_LINK so comments are welcome.

4
You attempt to link both static and dynamic versions of Boost.Thread. boost_thread is the import library for dll, libboost_thread is static library.Igor R.
why VS linking both, how to fix this issue?Oleg Vazhnev
Usually VS doesn't do this, so the question is what's wrong with your settings. Do you have BOOST_ALL_DYN_LINK defined? Do you link with CRT statically or dynamically (/MT or /MD)? Do you force linking some of the above libs (Linker-->Input-->Aditional dependencies or # pragma comment(lib,...))?Igor R.

4 Answers

7
votes

Edit: Initial statement removed since an edit to the post changed the situation.

Based on http://www.boost.org/doc/libs/1_53_0/more/getting_started/unix-variants.html#library-naming (as provided by Igor R.):

libboost_thread-vc110-mt-1_52.lib is a static lib (no need for the DLL) boost_thread-vc110-mt-1_52.lib is the import lib for the DLL

You only need to use one of these.

1
votes

Another idea/solution to try if you hit the error LNK1104: cannot open file 'libboost_date_time-*.lib' error:

In our project, we include the boost/date_time.hpp file. We define the constant BOOST_ALL_NO_LIB instead of BOOST_ALL_DYN_LINK in our project settings to tell boost not to automatically select which libraries to link against. See the Boost documentation for more information about this option.

So you could add BOOST_ALL_NO_LIB in Project Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions and check whether this linker error goes away.

0
votes

I think first of all you need to correct your question. Do you mean (I guess you already know the difference between DLL and LIB )

  • libboost_thread-vc110-mt-1_52.lib
  • boost_thread-vc110-mt-1_52.dll

or

  • libboost_thread-vc110-mt-1_52.lib
  • boost_thread-vc110-mt-1_52.lib

Anyway, it seems the issue is you're mixing static(libboost_thread-vc110-mt-1_52.lib) and shared (boost_thread-vc110-mt-1_52.lib) boost libraries. But without the working environment and platform details I cannot purpose an exact solution. If you work in Visual Studio ,then you can go to right click on project file > properties > linker > input > ignore specific library and add libboost_thread-vc110-mt-1_52.lib there and try.

0
votes

asking myquestion myself. need to uncomment #define BOOST_ALL_DYN_LINK (refer to description)