如何链接到动态提升库?

时间:2010-03-25 23:40:56

标签: c++ boost

我编译了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线程库编写了一个测试应用程序。基于代码生成设置,它只询问这四个lib(如多线程调试,多线程,多线程调试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代表什么?

3 个答案:

答案 0 :(得分:32)

您可以通过定义BOOST_ALL_DYN_LINK来强制Boost使用DLL - 在C ++预处理器设置中或在#define预编译头中的stdafx.h,例如:

#define BOOST_ALL_DYN_LINK

答案 1 :(得分:19)

要配置boost,请使用用户配置标头

<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

答案 2 :(得分:10)

  1. .lib文件是静态链接的,而.dll文件是动态链接的。我相信这是一个VC项目设置。

  2. 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