尝试链接 Boost 1.52 线程

Trying to link Boost 1.52 thread

本文关键字:线程 Boost 链接      更新时间:2023-10-16

我正在尝试编译我的程序,但它根本不会链接。我已经指定了 boost lib 文件的路径,但链接器仍然抱怨。这是我得到的链接错误:

1>Edproj.obj : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAABVerror_category@12@XZ)
1>Edproj.obj : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAABVerror_category@12@XZ)
1>Edproj.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall boost::detail::thread_data_base::~thread_data_base(void)" (??1thread_data_base@detail@boost@@UAE@XZ)
1>Edproj.obj : error LNK2001: unresolved external symbol "void __cdecl boost::throw_exception(class std::exception const &)" (?throw_exception@boost@@YAXABVexception@std@@@Z)
1>Edproj.obj : error LNK2001: unresolved external symbol "public: void __thiscall boost::thread::detach(void)" (?detach@thread@boost@@QAEXXZ)
1>Edproj.obj : error LNK2001: unresolved external symbol "public: void __thiscall boost::thread::join(void)" (?join@thread@boost@@QAEXXZ)
1>Edproj.obj : error LNK2001: unresolved external symbol "private: void __thiscall boost::thread::start_thread(void)" (?start_thread@thread@boost@@AAEXXZ)
1>Edproj.obj : error LNK2001: unresolved external symbol "bool __cdecl boost::this_thread::interruptible_wait(void *,struct boost::detail::timeout)" (?interruptible_wait@this_thread@boost@@YA_NPAXUtimeout@detail@2@@Z)

BOOST_LIB_DIAGNOSTIC回报

1>  Linking to lib file: libboost_thread-vc100-mt-s-1_52.lib
1>  Linking to lib file: libboost_date_time-vc100-mt-s-1_52.lib
1>  Linking to lib file: libboost_system-vc100-mt-s-1_52.lib
1>  Linking to lib file: libboost_chrono-vc100-mt-s-1_52.lib

更多信息:

我正在运行 64 位 Windows 8 专业版,我使用以下选项编译了 boost

bjam --build-type=complete --toolset=msvc10.0 address-model=64 architecture=x86 variant=debug,release threading=multi link=static runtime-link=static

有人可以告诉我出了什么问题吗?

更新:

更改为 boost 1.51 后,它摆脱了 7 个链接器错误中的 8 个,但这个仍然存在

error LNK2001: unresolved external symbol "void __cdecl boost::throw_exception(class std::exception const &)" (?throw_exception@boost@@YAXABVexception@std@@@Z)

我不明白这里发生了什么。这个来自 boostpro 32 位安装程序。它不可能与我的源文件有关,对吗?

更新:

好的,我已经解决了 boost 1.51 的这个问题。事实证明,在 C/C++>> 代码生成的属性页>>>>启用C++例外对我来说是关闭的。

还行。我将尝试查看相同的设置是否解决了 boost 1.52 的问题。稍后会更新。

我之前遇到过同样的问题:我使用直接运行引导.bat的默认参数构建 boost lib。

如果在项目中使用 boost::system

,则应使用并指定 x86 或 x64 版本的 boost::system lib。

您可以使用此 BAT 重新编译 Boost Lib,保存这些到 boost 根文件夹并在 CMD 窗口中运行它(不要双击!

call "%VS140COMNTOOLS%....VCvcvarsall.bat" x86
cd boost_1_60_0
call bootstrap.bat
rem Most libraries can be static libs
b2 -j8 toolset=msvc-14.0 address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/x64
b2 -j8 toolset=msvc-14.0 address-model=32 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/win32
pause

有关更多详细信息,请参阅此文章:https://studiofreya.com/2015/12/19/how-to-build-boost-1-60-with-visual-studio-2015/

谢谢在我看来

,它没有正确自动链接。

Include path is boost152/ only
Library path is boost152/stage/lib
请务必将

正确的目录添加到链接器属性中。

阅读这篇文章以了解更多详情Boost 链接器错误:未解析的外部符号"class boost::system::error_category const & __cdecl boost::system::get_system_category(void)"

此外,还必须将此路径添加到链接器添加目录中:

$(BOOST_ROOT)\bin.v2\libs\thread\build\msvc-xx.0\release\address-model-64\link-static\threading-multi

其中 xx 是您的 Visual Studio 版本

下面的

这两个定义弄乱了我的链接器,抛出了一个漂亮的"LNK2001:未解析的外部符号"错误。那么在你的代码中有某个地方吗?

//#define BOOST_FILESYSTEM_NO_DEPRECATED
//#define BOOST_FILESYSTEM_NO_LIB