Linking on Windows requires versioned boost libraries

For our CMake based C++ application we build boost ourselves as external project and add the libraries via target_link_libraries(). e.g. libboost_filesystem.a for Linux and macOS.

On Windows boost does by default not build with --layout=system with the system naming (libboost_filesystem.lib for static) but uses as default --layout=versioned which results e.g. in libboost_filesystem-vc143-mt-s-x64-1_81.lib but I want to build as system to share the target_link_libraries() over platforms.

When I configure our project with Intel’s oneAPI IntelLLVM compiler or with the default MSVC compiler, the linker output shows my desired libs but fails for missing libboost_serialization-vc143-mt-x64-1_81.lib or libboost_serialization-clangw16-mt-x64-1_81.lib. Note that this does not match the name I get when building boost with versioned layout (it has an additional ‘-s’).

I have not the slightest clue where this additional dependency is created. I already spent hours on figuring out - with not much success yet. There are versioned libs requested which are not in our add_target_libraries() e.g. libboost_zlib-vc143-mt-x64-1_81.lib.

I configure our project on command line as on Linux and macOS. We do not use find_package(BOOST) as we build it ourselves as external project.

Help is very much appreciated, as I have not the slightest clue where these dependencies are generated! Windows drives me cray - it is so cosy on macOS and Linux …

I suspect either cmake or the linker

[ 96%] Linking CXX executable ..\..\bin\cfs.exe
        cd C:\Users\fabia\code\master\release_msvc\source\main
        "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cfs.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests -- C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\MSVC\1434~1.319\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cfs.dir\objects1@C:\Users\fabia\AppData\Local\Temp\nm9DA4.tmp
Visual Studio Non-Incremental Link

Look for

#pragma lib

in the boost header files to find the answer.

1 Like

You can add the definition BOOST_ALL_NO_LIB to disable boost’s auto-linking. See the boost docs here: and do a search for BOOST_ALL_NO_LIB for some more info.

For others who are using CMake’s FindBoost module, you can achieve the same thing by adding the target Boost::disable_autolinking to your target link libraries. See for details.


Thanks a lot! I did not know about this. I should have asked earlier :slight_smile: