简体   繁体   English

使用boost进行编译时出错

[英]Error when compiling with boost

I writed project which uses <boost/thread/locks.hpp> , i added include directory to Additional Include directories , and lib folder to linker. 我写了一个使用<boost/thread/locks.hpp> ,我将include目录添加到Additional Include directories ,并将lib文件夹添加到链接器。 But when i try to build solution, error: 但是当我尝试构建解决方案时,错误:

Error 1 error LNK1104: cannot open file 'libboost_thread-vc100-mt-sgd-1_50.lib' 错误1错误LNK1104:无法打开文件'libboost_thread-vc100-mt-sgd-1_50.lib'

I searched this file in lib directory, but no file with this name in lib directory. 我在lib目录中搜索了这个文件,但在lib目录中没有这个名字的文件。 I found file with similar name libboost_thread-vc100-mt-gd-1_50 . 我找到了类似名称libboost_thread-vc100-mt-gd-1_50

What i'm doing wrong? 我做错了什么?

Your problem seems to be pretty similar to the one in this question . 您的问题似乎与此问题中的问题非常相似。 According to the naming conventions described here the only difference between the library the linker wants to use and the library you have is that the former links statically to the c++ standard library and the compiler runtime support libraries. 根据此处描述的命名约定,链接器要使用的库与您拥有的库之间的唯一区别是前者静态链接到c ++标准库和编译器运行时支持库。 I can think of two ways to solve this problem: 我可以想出两种方法来解决这个问题:

  1. Get the library the linker wants 获取链接器想要的库
    a. 一个。 If you used the boostpro installer: 如果您使用了boostpro安装程序:

    Make sure you check the box for Multithreaded debug, static runtime (I would recommend you mark them all) 确保你选中了Multithreaded debug, static runtime的框(我建议你全部标记)

    b. If you built the library yourself: 如果您自己构建了库:

    Open a console window 打开控制台窗口
    Change directory to your boost root 将目录更改为boost root
    The following command builds the required library: 以下命令构建所需的库:
    b2 toolset=msvc-10.0 --with-thread address-model=64 variant=debug link=static runtime-link=static runtime-debugging=on stage
    (I would recommend using: (我建议使用:
    b2 toolset=msvc-10.0 address-model=64 --build-type=complete stage ) b2 toolset=msvc-10.0 address-model=64 --build-type=complete stage

  2. Make the linker use the library you want 使链接器使用所需的库
    a. 一个。 Make autolink use the shared libraries 使自动链接使用共享库

    You can define BOOST_THREAD_DYN_LINK (to affect only the thread library) or BOOST_ALL_DYN_LIB (to affect all the boost libraries) before the inclusion of the header files (or preferably in your VC project preprocessor settings). 在包含头文件之前(或者最好在VC项目预处理器设置中),您可以定义BOOST_THREAD_DYN_LINK(仅影响线程库)或BOOST_ALL_DYN_LIB(以影响所有增强库)。 This would make the linker try to use the library boost_thread-vc100-mt-gd-1_50.lib (note that the lib- preffix is missing). 这将使链接器尝试使用库boost_thread-vc100-mt-gd-1_50.lib (请注意,缺少lib boost_thread-vc100-mt-gd-1_50.lib )。

    b. Disable autolink 禁用自动链接

    You can define BOOST_ALL_NO_LIB and then add the exact name of your library in your linker options 您可以定义BOOST_ALL_NO_LIB,然后在链接器选项中添加库的确切名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM