FindBoost: Boost_ARCHITECTURE not detected on MinGW
Problem Description
If the MinGW toolchain is used and the argument --layout=tagged or --layout=versioned is provided to Boost.Build (b2) during the built, the libraries are not found via find_package(Boost ...), if Boost_NO_BOOST_CMAKE=true is set, i.e. CMake's FindBoost module is used instead of Boost's CMake config files BoostConfig.cmake/boost-config.cmake are used.
The problem is the address-model tag -x32
or -x64
.
Workaround
Renaming the shared / import library files to ommit the address-model tag is a workaround. For example
- --layout=tagged
- libboost_atomic-mt-d-x64.dll -> libboost_atomic-mt-d.dll
- libboost_atomic-mt-d-x64.dll.a -> libboost_atomic-mt-d.dll.a
- --layout=versioned
- libboost_atomic-mgw93-mt-d-x64-1_72.dll -> libboost_atomic-mgw93-mt-d-1_72.dll
- libboost_atomic-mgw93-mt-d-x64-1_72.dll.a -> libboost_atomic-mgw93-mt-d-1_72.dll.a
Using --layout=system if MinGW is used, is a workaround.
Using Boost_NO_BOOST_CMAKE=false works, but has a limitation that Boost's CMake config files do not make it easy to link both debug and release libraries, which is a problem for multi-configuration generators.
I am using CMake to build both Eclipse CDT (MinGW) projects and Microsoft VS2019 solutions. The problem does not occur using MSVC as a compiler!
My solution until one of these bugs/limitations is solved is to do one of the following things:
if(MINGW)
#set( boost_LAYOUT "system")
set( Boost_NO_BOOST_CMAKE false)
else()
#set( boost_LAYOUT "versioned")
set( Boost_NO_BOOST_CMAKE true)
endif()