Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm just getting started with Boost for the first time, details:

  1. I'm using Visual Studio 2008 SP1
  2. I'm doing an x64 Build
  3. I'm using boost::asio only (and any dependencies it has)

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:

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

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.

like image 497
Alex Black Avatar asked Jun 30 '09 21:06

Alex Black


People also ask

How do you fix unresolved externals in C++?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.

How do I fix unresolved external symbol lnk2001?

To fix this issue, add the /NOENTRY option to the link command. This error can occur if you use incorrect /SUBSYSTEM or /ENTRY settings in your project. For example, if you write a console application and specify /SUBSYSTEM:WINDOWS, an unresolved external error is generated for WinMain .

What is unresolved external error?

Answer. Unresolved external references occur when the symbol for a function or global variable is referenced in a program, but none of the object files or libraries specified in the link step contain a definition for that symbol.


2 Answers

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 
like image 98
Alex Black Avatar answered Oct 04 '22 09:10

Alex Black


#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.

like image 21
Jeffrey Faust Avatar answered Oct 04 '22 09:10

Jeffrey Faust