2010-03-25 61 views
26

我編譯了boost lib並獲得了這些。如何鏈接到動態提升庫?

//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 

在Visual Studio中,我使用boost線程庫編寫了測試應用程序。基於代碼生成設置,它要求只有這四個庫(如多線程調試,多線程,多線程調試DLL和多線程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 

現在的問題是如何將我的應用程序鏈接到其他2個庫等等它使用dll?

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 

問題2. g,s代表什麼?

回答

9
  1. .lib文件是靜態鏈接的,而.dll文件是動態鏈接的。我相信這是一個VC項目設置。

 
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. 

來源:http://old.nabble.com/Build-statically-linked-boost-libs- * -vc90-MT-sgd.lib-td16301103.html

+6

更好出處:http://www.boost .ORG/DOC /庫/ 1_42_0 /多/ getting_started/windows.html#庫命名 – 2010-03-26 09:34:13

28

您可以強制加速通過定義BOOST_ALL_DYN_LINK使用DLL文件 - 無論是在你的C++預處理器設置或stdafx.h預編譯頭文件中的#define,例如:

#define BOOST_ALL_DYN_LINK

18

配置提升使用用戶配置頭

<boost/config/user.hpp> 

接着尋找動態鏈接線並更改所需配置

// 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