如何链接到动态提升库?
Posted
技术标签:
【中文标题】如何链接到动态提升库?【英文标题】:How to link to dynamic boost libs? 【发布时间】:2010-03-25 23:40:55 【问题描述】:我编译了 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 代表什么?
【问题讨论】:
【参考方案1】:您可以通过定义 BOOST_ALL_DYN_LINK
来强制 Boost 使用 DLL - 在您的 C++ 预处理器设置中或在您的 stdafx.h
预编译头文件中定义 #define
,例如:
#define BOOST_ALL_DYN_LINK
【讨论】:
【参考方案2】:要配置 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
【讨论】:
【参考方案3】:.lib 文件是静态链接的,而 .dll 文件是动态链接的。我相信这是一个 VC 项目设置。
来源:http://old.nabble.com/Build-statically-linked-boost-libs-*-vc90-mt-sgd.lib-td16301103.html
【讨论】:
更好的来源:boost.org/doc/libs/1_42_0/more/getting_started/… 更好的来源boost.org/build/doc/html/bbv2/overview/invocation.html 更新链接:boost.org/doc/libs/1_70_0/more/getting_started/…以上是关于如何链接到动态提升库?的主要内容,如果未能解决你的问题,请参考以下文章