28

我刚刚开始第一次使用 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)

有任何想法吗?


我添加了这个定义:#define 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

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

4

10 回答 10

44

我解决了这个问题。当我打算构建 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
于 2009-07-01T02:54:56.373 回答
5
#include <boost/system/config.hpp>

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

于 2014-10-08T17:07:44.280 回答
1

您需要在 boost_system 库中链接

于 2009-06-30T21:12:55.457 回答
1

如果您在项目中使用boost::system,则应使用并指定 x86 或 x64 版本的 boost::system 库。

您可以使用以下批处理文件重新编译 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/

于 2016-05-29T03:53:39.713 回答
1

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

于 2017-01-22T13:47:02.817 回答
0

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

事实证明,在我的情况下,链接器错误是由于错误造成的:

    add_definitions(-DBOOST_ALL_DYN_LINK)

在 中CMakeLists.txt,这对 Unix 很好,但在我的情况下不是 Windows。解决方案不是在 Windows 上使用该定义。

于 2015-08-05T12:47:23.833 回答
0

我需要两个版本并使用舞台目标,所以我使用 --stagedir=./stageX86 用于 x86 版本和默认 ./stage 用于 x64

于 2015-08-19T12:35:43.327 回答
0

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

cmake -Ax64 {path to CMakeLists.txt}
于 2016-07-01T16:02:06.363 回答
0

之前在这个线程中给出的方法都没有对我有用。然后我检查了boost系统文件夹中的文件并在#define下面尝试

#define BOOST_ERROR_CODE_HEADER_ONLY

使用此链接后,链接错误得到解决。

于 2020-03-29T15:52:50.010 回答
0

就我而言,我通过将 boost include dir 从

Project -> Properties-> VC++ Directories -> Include Directories

Project -> Properties-> C/C++ -> General -> Additional Include Directories

, 并将 boost lib 目录从

Project -> Properties-> VC++ Directories -> Library Directories

Project -> Properties-> Linker -> General -> Additional Library Directories

可能错误是由链接顺序引起的。

于 2020-09-30T08:16:20.737 回答