Search code examples
visual-c++boostvisual-studio-2022

Boost log linker errors (LNK2001/LNK2019 unresolved external symbol) after upgrading to Windows 11 and rebuilding boost


I had boost compiled & working on my Visual Studio 2022 project. After the PC was upgraded and the OS changed to Windows 11 I attempted to re-build boost and use it with the same project. Now I get linker errors, and it seems like I have tried every suggested fix posted online. Somehow it seems like the lib files are not being found, even though I have confirmed the include and lib directories are included properly, and have tried rebuilding boost with many different configurations.

The boost build produces libboost_*.lib files, for example

libboost_log_setup-vc143-mt-gd-x32-1_78.lib

libboost_log_setup-vc143-mt-x32-1_78.lib

libboost_log-vc143-mt-gd-x32-1_78.lib

libboost_log-vc143-mt-x32-1_78.lib

Here are my boost build options

x86

b2 -j 16 --stagedir=stage/Win32 threading=multi --toolset=msvc-14.3 link=static runtime-link=shared --build-type=complete architecture=x86 address-model=32

x64

b2 -j 16 --stagedir=stage/x64 threading=multi --toolset=msvc-14.3 link=static runtime-link=shared --build-type=complete architecture=x64 --address-model=64

And my Visual Studio properties

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

C:\Program Files\Code Libraries\boost\boost_1_78_0

Linker->General->Additional Library Directories

C:\Program Files\Code Libraries\boost\boost_1_78_0\stage$(Platform)\lib

And here's an example of the errors

1>Logging.obj : error LNK2019: unresolved external symbol "private: static unsigned int __cdecl boost::log::v2s_mt_nt62::attribute_name::get_id_from_string(char const *)" (?get_id_from_string@attribute_name@v2s_mt_nt62@log@boost@@CAIPBD@Z) referenced in function "public: __thiscall boost::log::v2s_mt_nt62::attribute_name::attribute_name(char const *)" (??0attribute_name@v2s_mt_nt62@log@boost@@QAE@PBD@Z)
1>Logging.obj : error LNK2001: unresolved external symbol "public: static void __cdecl boost::log::v2s_mt_nt62::aux::stream_provider<char>::release_compound(struct boost::log::v2s_mt_nt62::aux::stream_provider<char>::stream_compound *)" (?release_compound@?$stream_provider@D@aux@v2s_mt_nt62@log@boost@@SAXPAUstream_compound@12345@@Z)
1>Logging.obj : error LNK2019: unresolved external symbol "public: static void * __cdecl boost::log::v2s_mt_nt62::attribute::impl::operator new(unsigned int)" (??2impl@attribute@v2s_mt_nt62@log@boost@@SAPAXI@Z) referenced in function "class boost::log::v2s_mt_nt62::attribute_value __cdecl boost::log::v2s_mt_nt62::attributes::make_attribute_value<unsigned int &>(unsigned int &)" (??$make_attribute_value@AAI@attributes@v2s_mt_nt62@log@boost@@YA?AVattribute_value@123@AAI@Z)
1>Logging.obj : error LNK2019: unresolved external symbol "public: static void __cdecl boost::log::v2s_mt_nt62::attribute::impl::operator delete(void *,unsigned int)" (??3impl@attribute@v2s_mt_nt62@log@boost@@SAXPAXI@Z) referenced in function __unwindfunclet$??$make_attribute_value@AAI@attributes@v2s_mt_nt62@log@boost@@YA?AVattribute_value@123@AAI@Z$0

Edit: I also wanted to mention my preprocessor variables for Debug/Win32

WIN32 _DEBUG _CONSOLE WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0A00

I haven't been able to find a _WIN32_WINNT value for Windows 11, and I thought maybe that could be the problem. But I'm not entirely sure that matters.


Solution

  • The problem is that Boost, and Boost.Log in particular, was built for a different Windows version. You need to either:

    • Build Boost with _WIN32_WINNT defined to the same version as you define when you build your code.
    • Define BOOST_USE_WINAPI_VERSION when building your code to the Windows version Boost should target, which would be lower than your _WIN32_WINNT. Also define _WIN32_WINNT or BOOST_USE_WINAPI_VERSION macro to that version when building Boost.

    To define the macro when building Boost add define=macro=value to the b2 command line. For example, define=_WIN32_WINNT=0x0A00.