Resolving issues linking with Boost libraries on Windows


Tags: windows c++ boost

Scenario: I was attempting to get my C++ CMake Qt/Boost based project building on Windows.

I was getting linking errors such as:

LNK2019: unresolved external symbol "private: class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >

Solution: Ensure Boost has been built for the correct architecture! (x86 vs x64)

Steps taken:

  1. Installed Visual Studio Express 2013 Desktop (VS 2015 is still in RC)
  2. Installed the Windows 8.1 SDK
  3. Installed the Qt SDK including QtCreator
  4. installed CMake
  5. Installed Boost
    1. Extracted Boost download to C:\Program Files\boost_1_58_0
    2. Opened a VS2013 x64 Cross Tools command prompt
    3. Run bootstrap.bat in the boost directory
    4. Built 64 bit Boost libraries. This was the crucial part I had missed before, and by default b2 was generating x86 libraries. The address-model parameter is the key part C:\Program Files\boost_1_58_0>b2 --toolset=msvc-12.0 architecture=x86 address-model=64 --with-regex --with-system --with-filesystem --build-type=complete stage
    5. Verify the libraries generated are 64 bit using the dumpbin tool. Look to see the “Machine” line says (x64).The libraries will have been output into stage\lib in the previous step C:\Program Files\boost_1_58_0\stage\lib\>dumpbin /headers *.lib Version : 0 Machine : 8664 (x64) TimeDateStamp: 55463452 Sun May 03 15:44:34 2015 SizeOfData : 00000058 DLL name : boost_filesystem-vc120-mt-1_58.dll Symbol name : ?absolute@filesystem@boost@@YA?AVpath@12@AEBV312@0@Z (class boo st::filesystem::path __cdecl boost::filesystem::absolute(class boost::filesystem ::path const &,class boost::filesystem::path const &)) Type : code Name type : name Hint : 46 Name : ?absolute@filesystem@boost@@YA?AVpath@12@AEBV312@0@Z
  6. Success!