动态链接boost库和自动链接不能正常工作
Dynamic linking boost libraries and the auto-link not working properly?
我使用以下命令在Win7 Pro
和VS 2013 Pro (VC12.0, 18.00.21005.1)
上构建boost-1.53.0
:
b2 stage toolset=msvc link=shared runtime-link=shared threading=multi --without-graph --without-graph_parallel --without-mpi --without-wave --without-python
在此之前,我修补了我的源代码,按照这个补丁:#8750 for_vs2013.patch.
最后我得到了$BOOST_ROOT/stage/lib
下面的文件,像这样:
boost_atomic-vc120-mt-1_53.dll
boost_atomic-vc120-mt-1_53.lib
boost_atomic-vc120-mt-gd-1_53.dll
boost_atomic-vc120-mt-gd-1_53.lib
...
boost_thread-vc120-mt-1_53.dll
boost_thread-vc120-mt-1_53.lib
boost_thread-vc120-mt-gd-1_53.dll
boost_thread-vc120-mt-gd-1_53.lib
...
// only theses four files have "lib" prefix
libboost_exception-vc120-mt-1_53.lib
libboost_exception-vc120-mt-gd-1_53.lib
libboost_test_exec_monitor-vc120-mt-1_53.lib
libboost_test_exec_monitor-vc120-mt-gd-1_53.lib
构建boost::signals
库失败。因为我不知道这是否与这个问题有关,所以我在这里澄清一下。
我写了一个非常简单的演示来学习boost::thread
根据教程刚才。但是编译器给了我一个链接错误:LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc120-mt-gd-1_53.lib'
。我找了一下,有个问题。我确定我已经将Project Properties > C/C++ > Code Generation > Runtime Library
设置为/MDd
了。但是为什么编译器仍然试图链接静态库libboost_thread-vc120-mt-gd-1_53.lib
当我重建项目?我也尝试使用一些相对的解决方案,我发现,如使用BOOST_ALL_DYN_LINK
或BOOST_DYN_LINK
预编译指令。但这行不通。我在auto-link.hpp
中发现了这样一个片段:
//
// select linkage opt:
//
#if (defined(_DLL) || defined(_RTLDLL)) && defined(BOOST_DYN_LINK)
# define BOOST_LIB_PREFIX
#elif defined(BOOST_DYN_LINK)
# error "Mixing a dll boost library with a static runtime is a really bad idea..."
#else
# define BOOST_LIB_PREFIX "lib"
#endif
它应该工作,但我不能得到我想要的结果:(
顺便说一句,我应该用link=static
选项重建boost库吗?
// c++ std libraries
#include <iostream>
// c++ boost libraries
#include <boost/thread.hpp>
#include <boost/date_time.hpp>
// #define BOOST_ALL_DYN_LINK
// #define BOOST_DYN_LINK
void WorkerFunc()
{
boost::posix_time::seconds worktime(3);
std::cout << "Worker: running..." << std::endl;
// Pretend to do sth. useful...
boost::this_thread::sleep(worktime);
std::cout << "Worker: finished." << std::endl;
}
int main()
{
std::cout << "main: startup." << std::endl;
// Create a worker thread.
boost::thread worker_thread(WorkerFunc);
std::cout << "main: waiting for thread..." << std::endl;
worker_thread.join();
std::cout << "main: done." << std::endl;
return 0;
}
从visual studio内部:转到您的项目并右键单击它以获得上下文菜单。转到属性。在属性对话框中进入:
配置属性->C/c++ ->预处理器->预处理器定义
尝试将BOOST_ALL_DYN_LINK(或BOOST_THREAD_USE_DLL)放在预处理器定义列表中。
- 我似乎无法让 msvc 链接器在 vscode 上正常工作
- 在调试配置中编译工作正常,但发布会给出链接错误
- 当我在C 程序中加入RINSIDE标头时,如何使链接器工作
- 重载按位 OR('|'),用于链接操作无法按预期工作
- 如何包括使用软链接的工作
- 仅一个功能的链接错误.在同一类和CPP文件中具有相似签名的其他函数工作正常
- 如何使用字符串更改此插入功能以在链接列表中工作
- MySql connector-c++不会在QtCreator中链接,但在Raspberry pi3上本地工作正常
- 如何设计一个配置实用程序来静态和动态链接工作
- 如何使此链接列表正常工作
- 模板隐式专业化和链接,它是如何工作的?
- 针对库链接但直接传递obj文件的未解析名称可以正常工作
- 动态链接是如何工作的,它的用法以及如何以及为什么要制作dylib
- 链接究竟是如何工作的
- 文件之间的链接 - 它究竟是如何工作的
- 无法使用VS2012链接到静态升压库,而动态链接工作正常
- 链接错误(#ifndef 无法按预期工作)
- MS链接从gnu-make失败,但从cmd行工作
- SFML 2.1代码::Blocks静态链接不工作
- libx264链接不工作(Cygwin)