How to link to dynamic boost libs?
I compiled boost lib and got these.
//Shared/dynamic link libraries
24/03/2010 11:25 PM 53,248 boost_thread-vc80-mt-1_42.dll
24/03/2010 11:25 PM 17,054 boost_thread-vc80-mt-1_42.lib
24/03/2010 11:25 PM 17,054 boost_thread-vc80-mt.lib
24/03/2010 11:25 PM 73,728 boost_thread-vc80-mt-gd-1_42.dll
24/03/2010 11:25 PM 17,214 boost_thread-vc80-mt-gd-1_42.lib
24/03/2010 11:25 PM 17,214 boost_thread-vc80-mt-gd.lib
// Static libs... does not need any dlls
24/03/2010 11:25 PM 381,716 libboost_thread-vc80-mt-1_42.lib
24/03/2010 11:25 PM 381,716 libboost_thread-vc80-mt.lib
24/03/2010 11:25 PM 999,552 libboost_thread-vc80-mt-gd-1_42.lib
24/03/2010 11:25 PM 999,552 libboost_thread-vc80-mt-gd.lib
24/03/2010 11:25 PM 421,050 libboost_thread-vc80-mt-s-1_42.lib
24/03/2010 11:25 PM 421,050 libboost_thread-vc80-mt-s.lib
24/03/2010 11:25 PM 1,015,688 libboost_thread-vc80-mt-sgd-1_42.lib
24/03/2010 11:25 PM 1,015,688 libboost_thread-vc80-mt-sgd.lib
In Visual Studio, I have written a test app using the boost thread library. Based on code generation settings it asks for these four libs only (like multithreading debug, multithreading, multithreading debug dll, and multithreading dll)
24/03/2010 11:25 PM 381,716 libboost_thread-vc80-mt-1_42.lib
24/03/2010 11:25 PM 381,716 libboost_thread-vc80-mt.lib
24/03/2010 11:25 PM 999,552 libboost_thread-vc80-mt-gd-1_42.lib
24/03/2010 11:25 PM 999,552 libboost_thread-vc80-mt-gd.lib
24/03/2010 11:25 PM 421,050 libboost_thread-vc80-mt-s-1_42.lib
24/03/2010 11:25 PM 421,050 libboost_thread-vc80-mt-s.lib
24/03/2010 11:25 PM 1,015,688 libboost_thread-vc80-mt-sgd-1_42.lib
24/03/2010 11:25 PM 1,015,688 libboost_thread-vc80-mt-sgd.lib
Now my question is how can I link my app to the other 2 libs so that it uses the dlls?
24/03/2010 11:25 PM 53,248 boost_thread-vc80-mt-1_42.dll
24/03/2010 11:25 PM 17,054 boost_thread-vc80-mt-1_42.lib
24/03/2010 11:25 PM 17,054 boost_thread-vc80-mt.lib
24/03/2010 11:25 PM 73,728 boost_thread-vc80-mt-gd-1_42.dll
24/03/2010 11:25 PM 17,214 boost_thread-vc80-mt-gd-1_42.lib
24/03/2010 11:25 PM 17,214 boost_thread-vc80-mt-gd.lib
Question 2. What does the g, s stands for?
Solution 1:
You can force Boost to use the DLLs by defining BOOST_ALL_DYN_LINK
- either in your C++ preprocessor settings or by a #define
in your stdafx.h
pre-compiled header, e.g.:
#define BOOST_ALL_DYN_LINK
Solution 2:
To configure boost use the user config header
<boost/config/user.hpp>
Then just look for the dynamic link lines and change to your desired configuration
// BOOST_ALL_DYN_LINK: Forces all libraries that have separate source,
// to be linked as DLL's rather than static libraries on Microsoft Windows
// (this macro is used to turn on __declspec(dllimport) modifiers, so that
// the compiler knows which symbols to look for in a DLL rather than in a
// static library). Note that there may be some libraries that can only
// be statically linked (Boost.Test for example) and others which may only
// be dynamically linked (Boost.Threads for example), in these cases this
// macro has no effect.
// #define BOOST_ALL_DYN_LINK
Solution 3:
The .lib files are linked statically, while .dll files are linked dynamically. I believe it's a VC project setting.
The "lib" prefix is for static libraries. Use link=static The 's' letter is to static linking to runtime. Use runtime-link=static The 'd' is debug, use variant=debug The 'g' is using debug runtime, I think it's included in 'debug' variant already. If not runtime-debugging=on will help.
Source: http://old.nabble.com/Build-statically-linked-boost-libs-*-vc90-mt-sgd.lib-td16301103.html