28

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.

Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
waterlooalex
  • 13,642
  • 16
  • 78
  • 99

10 Answers10

44

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
waterlooalex
  • 13,642
  • 16
  • 78
  • 99
  • You can test your libs are for the correct platform with this: http://stackoverflow.com/questions/6014107/have-a-static-lib-is-there-a-simple-way-to-know-it-is-for-32-bit-or-64-bit – Scott Langham Mar 04 '15 at 18:58
  • 1
    Before address-model I had a '-' that shouldn't be there. – Scott Langham Mar 04 '15 at 19:58
  • This was good inspiration to find my bug, I was in a somewhat mirror situation where I built the boost libs as x64 but was building a new application as Win32 and trying to link to libraries that were built as x64. I forgot that template projects in Visual Studio create default configurations that get plugged into the ConfigurationManager rather than assuming what the current solution configuartion is. – jxramos Apr 28 '16 at 19:24
5
#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.

Jeffrey Faust
  • 547
  • 3
  • 12
1

You need to link in the boost_system library

Maik Beckmann
  • 5,637
  • 1
  • 23
  • 18
  • 1
    Does it not get auto-linked in? The other libraries seem to. Whats the correct way to link it in? (Given all the variations of the library etc) – waterlooalex Jun 30 '09 at 21:15
  • Funny thing is, the first error I got was: fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-1_38.lib'. I then made sure that library was in the lib path and it went away. – waterlooalex Jun 30 '09 at 21:17
  • 1
    Add the import library (boost_system.??.lib) at your Project settings. – Maik Beckmann Jun 30 '09 at 21:21
  • 1
    I added libboost_system-vc90-mt-1_38.lib to my list of libraries, same error. – waterlooalex Jun 30 '09 at 22:00
1

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/

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Protoss
  • 512
  • 7
  • 27
1

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

Pavel
  • 11
  • 1
0

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.

Barry
  • 606
  • 7
  • 13
0

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

Eugenio Miró
  • 2,398
  • 2
  • 28
  • 38
0

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}
Joe Staines
  • 301
  • 1
  • 3
  • 11
0

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

#define BOOST_ERROR_CODE_HEADER_ONLY

The linking error is solved after using this.

Rishabh
  • 31
  • 3
0

In my case, I resolved this by moving the boost include dir from

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

to

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

, and moving the boost lib dir from

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

to

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

Maybe the error is caused by link order.

Huang C
  • 23
  • 5