Boost linker error: Unresolved external symbol “class boost::system::error_category const & __cdecl boost::system::get_system_category(void)”

岁酱吖の 提交于 2019-11-27 08:50:04
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.

Here is my bjam command line:

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>

In my case, BOOST_LIB_DIAGNOSTIC did not show system being automatically linked in. I resolved this by simply including boost/system/config.hpp.

You need to link in the boost_system library

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

Protoss

If you use boost::system in your project, you should use and appoint the x86 or x64 version of boost::system lib.

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!):

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/

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.

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.

I needed both versions and used stage target, so I used --stagedir=./stageX86 for x86 version and the default ./stage for x64

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 -Ax64 {path to CMakeLists.txt}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!