Error when compiling with boost

2019-05-04 00:07发布

I writed project which uses <boost/thread/locks.hpp>, i added include directory to Additional Include directories, and lib folder to linker. But when i try to build solution, error:

Error 1 error LNK1104: cannot open file 'libboost_thread-vc100-mt-sgd-1_50.lib'

I searched this file in lib directory, but no file with this name in lib directory. I found file with similar name libboost_thread-vc100-mt-gd-1_50.

What i'm doing wrong?

1条回答
何必那么认真
2楼-- · 2019-05-04 00:44

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. I can think of two ways to solve this problem:

  1. Get the library the linker wants
    a. If you used the boostpro installer:

    Make sure you check the box for Multithreaded debug, static runtime (I would recommend you mark them all)

    b. If you built the library yourself:

    Open a console window
    Change directory to your 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)

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

    b. Disable autolink

    You can define BOOST_ALL_NO_LIB and then add the exact name of your library in your linker options

查看更多
登录 后发表回答