C++ Boost 链接器错误:未解析的外部符号“class boost::system::error_category const & __cdecl boost::system::get_system_category(void)”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1066071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Boost linker error: Unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::get_system_category(void)"
提问by Alex Black
I'm just getting started with Boost for the first time, details:
我是第一次开始使用 Boost,详细信息:
- I'm using Visual Studio 2008 SP1
- I'm doing an x64 Build
- I'm using boost::asio only (and any dependencies it has)
- 我使用的是 Visual Studio 2008 SP1
- 我正在做一个 x64 构建
- 我只使用 boost::asio(以及它具有的任何依赖项)
My code now compiles, and I pointed my project at the boost libraries (after having built x64 libs) and got past simple issues, now I am facing a linker error:
我的代码现在可以编译,我将我的项目指向 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)
any ideas?
有任何想法吗?
I added this define: #define BOOST_LIB_DIAGNOSTIC
我添加了这个定义:#define BOOST_LIB_DIAGNOSTIC
And now in my output I see this:
现在在我的输出中我看到了这个:
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
which seems to indicate it is infact linking in the system lib.
这似乎表明它实际上是在系统库中链接。
回答by Alex Black
I solved the problem. I had built 32-bit libraries when I had intended to build 64-bit libraries. I fixed up my build statement, and built 64-bit libraries, and now it works.
我解决了这个问题。当我打算构建 64 位库时,我已经构建了 32 位库。我修正了我的构建语句,并构建了 64 位库,现在它可以工作了。
Here is my bjam command line:
这是我的 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
回答by Jeffrey Faust
#include <boost/system/config.hpp>
In my case, BOOST_LIB_DIAGNOSTIC did not show system being automatically linked in. I resolved this by simply including boost/system/config.hpp.
在我的例子中,BOOST_LIB_DIAGNOSTIC 没有显示系统被自动链接。我通过简单地包含 boost/system/config.hpp 解决了这个问题。
回答by Maik Beckmann
You need to link in the boost_system library
您需要在 boost_system 库中进行链接
回答by Protoss
If you use boost::systemin your project, you should use and appoint the x86 or x64 version of boost::system lib.
如果您在项目中使用boost::system,则应使用并指定 x86 或 x64 版本的 boost::system 库。
You can recompile Boost library with the following batch file. Save these to the Boost root folder and run it in CMD Windows (don't double click!):
您可以使用以下批处理文件重新编译 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
For more details, you can see this article: https://studiofreya.com/2015/12/19/how-to-build-boost-1-60-with-visual-studio-2015/
更多详情可以看这篇文章:https: //studiofreya.com/2015/12/19/how-to-build-boost-1-60-with-visual-studio-2015/
回答by Pavel
I had the same problem. I tried all described above, but nothing helps. The solution was simple: first I worked with an empty project and there I had linker error LNK2019. But when I created new default Win32 console application with stdafx.h, targetver.h and stdafx.cpp files everything worked. May be it will be useful for somebody, I spend two days for this
我有同样的问题。我尝试了上述所有内容,但没有任何帮助。解决方案很简单:首先我使用一个空项目,在那里我遇到了链接器错误 LNK2019。但是当我使用 stdafx.h、targetver.h 和 stdafx.cpp 文件创建新的默认 Win32 控制台应用程序时,一切正常。可能对某人有用,我花了两天时间
回答by Rishabh
None of the methods worked for me given before in this thread. Then I checked the files inside boost system folder and tried below #define
在这个线程中之前给出的方法都不适合我。然后我检查了boost系统文件夹中的文件并在#define下面尝试
#define BOOST_ERROR_CODE_HEADER_ONLY
#define BOOST_ERROR_CODE_HEADER_ONLY
The linking error is solved after using this.
使用这个之后链接错误就解决了。
回答by Joe Staines
I also came here from for this linker error plus CMake, but in my case it was the fact that CMake by default will try to build with 32bit by default. This was fixed by specifying -Ax64
我也是为了这个链接器错误和 CMake 来到这里的,但在我的情况下,CMake 默认情况下会尝试使用 32 位构建。这是通过指定修复的-Ax64
cmake -Ax64 {path to CMakeLists.txt}
回答by Barry
I came to the question via searching for the linker error plus CMAKE, so I'm adding this comment here in case anyone else finds this question the same way.
我是通过搜索链接器错误和 CMAKE 来解决这个问题的,所以我在这里添加了这条评论,以防其他人以同样的方式发现这个问题。
It turns out that the linker error in my case was due to an errant:
事实证明,我的情况下的链接器错误是由于错误造成的:
add_definitions(-DBOOST_ALL_DYN_LINK)
in the CMakeLists.txt
, which is fine for Unix, but not Windows in my case. The solution is not use that define on Windows.
在 中CMakeLists.txt
,这适用于 Unix,但在我的情况下不适用于 Windows。解决方案不是使用在 Windows 上定义的。
回答by Eugenio Miró
I needed both versions and used stage target, so I used --stagedir=./stageX86 for x86 version and the default ./stage for x64
我需要两个版本并使用 stage 目标,所以我使用 --stagedir=./stageX86 for x86 版本和默认 ./stage for x64