增强链接器错误:无法解析的外部符号“class boost::system::error_category const & __cdecl boost::system::get_system_category(void)”

StackOverflow https://stackoverflow.com/questions/1066071

我刚刚开始第一次使用Boost,详细信息:

  1. 我使用的是 Visual Studio 2008 SP1
  2. 我正在进行 x64 构建
  3. 我仅使用 boost::asio (以及它具有的任何依赖项)

我的代码现在可以编译,我将我的项目指向 boost 库(在构建 x64 库之后)并解决了简单的问题,现在我面临链接器错误:

2>BaseWebServer.obj : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::get_system_category(void)" (?get_system_category@system@boost@@YAAEBVerror_category@12@XZ)
2>BaseWebServer.obj : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::get_generic_category(void)" (?get_generic_category@system@boost@@YAAEBVerror_category@12@XZ)

有任何想法吗?


我添加了这个定义:#定义 BOOST_LIB_DIAGNOSTIC

现在在我的输出中我看到了这个:

1>Linking to lib file: libboost_system-vc90-mt-1_38.lib
1>Linking to lib file: libboost_date_time-vc90-mt-1_38.lib
1>Linking to lib file: libboost_regex-vc90-mt-1_38.lib

这似乎表明它实际上是在系统库中链接的。

有帮助吗?

解决方案

我解决了这个问题。当我打算构建 64 位库时,我已经构建了 32 位库。我修复了构建语句并构建了 64 位库,现在它可以工作了。

这是我的 bjam 命令行:

C:\Program Files (x86)\boost\boost_1_38>bjam --build-dir=c:\boost --build-type=complete --toolset=msvc-9.0 address-model=64 architecture=x86 --with-system

其他提示

#include <boost/system/config.hpp>

就我而言,BOOST_LIB_DIAGNOSTIC 没有显示系统被自动链接。我通过简单地包含 boost/system/config.hpp 解决了这个问题。

您需要链接到 boost_system 库

我有同样的问题。我尝试了上述所有内容,但没有任何帮助。解决方案很简单:首先,我使用一个空项目,并出现链接器错误 LNK2019。但是,当我使用 stdafx.h、targetver.h 和 stdafx.cpp 文件创建新的默认 Win32 控制台应用程序时,一切正常。可能对某人有用,我花了两天时间

如果你使用 提升::系统 在你的项目中,你应该使用并指定x86或x64版本的boost::system lib。

您可以使用以下批处理文件重新编译 Boost 库。将它们保存到 Boost 根文件夹并在 CMD Windows 中运行它(不要双击!):

call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x86


cd boost_1_60_0
call bootstrap.bat

rem Most libraries can be static libraries
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/

我通过搜索链接器错误加上 CMAKE 来解决这个问题,所以我在这里添加此评论,以防其他人以同样的方式发现这个问题。

事实证明,在我的例子中,链接器错误是由于错误造成的:

    add_definitions(-DBOOST_ALL_DYN_LINK)

在里面 CMakeLists.txt, ,这对于 Unix 来说没问题,但在我的例子中却不适用于 Windows。解决方案是不使用 Windows 上的定义。

我需要两个版本并使用 stage 目标,因此我对 x86 版本使用 --stagedir=./stageX86 ,对 x64 版本使用默认 ./stage

我也是因为这个链接器错误加上 CMake 来到这里的,但就我而言,事实上 CMake 默认情况下会尝试使用 32 位进行构建。这是通过指定修复的 -Ax64

cmake -Ax64 {path to CMakeLists.txt}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top