动态链接提升库和自动链接无法正常工作?

时间:2014-05-04 11:24:38

标签: c++ boost linker-errors boost-thread dynamic-linking

我使用以下命令在boost-1.53.0上使用Win7 Pro构建VS 2013 Pro (VC12.0, 18.00.21005.1)

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

它应该有效,但我无法得到我想要的结果:(

BTW,我应该用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;
}

1 个答案:

答案 0 :(得分:0)

从visual studio内部:转到您的项目并右键单击它以获取上下文菜单。转到属性。在属性对话框中,转到:

配置属性 - &gt; C / C ++ - &gt;预处理器 - &gt;预处理器定义

尝试将BOOST_ALL_DYN_LINK(或BOOST_THREAD_USE_DLL)放入预处理程序定义列表中。

然后重建你的演示。