how to build boost 1.79 with "clang-cl" under Windows?
i've got a working LLVM 14.x/clang-cl installation (means working with cmake/ninja etc. with my non boost projects) and working boost builds for 32/64 bit with VS2017,2019,2022,mingw aka a "good working environment" for my boost projects i tried to use my VS2017 built libs by forcing the toolkit name with set(Boost_COMPILER "vc141") in my root CMakeLists.txt cmake -G Ninja -DCMAKE_C_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" ../myproject that does not work for all linking (sometimes lld-link.exe complains about missing libboost_unit_test_framework-clangw14-mt-gd-x64-1_79.lib etc. (with the wrong "clangw14" in the name) im always using boosts own cmake configuration using the CONFIG parameter with cmakes find_package find_package(Boost CONFIG REQUIRED COMPONENTS unit_test_framework filesystem system) and i've checked that Boost_COMPILER is always "vc141" before find_package call do i miss something or does Boost_COMPILER does not work properly with boost own cmake config ? the other idea was to build boost directly with clang-cl in an VS2017 build environment inside my current boost build folder (where are the lib32-msvc-14.1, lib64-msvc-14.1 etc. b2 build folders resist) i tried to build with toolkit=clang without and beeing in a VS2017 build environment with C:\Program Files\LLVM\bin in my path using that b2 commandline for building b2 -j%NUMBER_OF_PROCESSORS% toolset=clang address-model=64 --stagedir=.\lib64-clang-14.0 --build-dir=.\__build --build-type=complete threading=multi architecture=x86 stage --with-date_time --with-graph --with-nowide --with-test --width-config --with-system --with-filesystem --with-serialization but that fails with linker errors (https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools...) any tutorial how to force building boost with clang-cl instead of cl using the microsoft libraries etc. as usual? there is no clang-cl or clangw toolkit setting available to my understanding
this is a small test to get the linker error
CMakeLists.txt
cmake_minimum_required(VERSION 3.18)
project(example)
find_package(Boost CONFIG REQUIRED COMPONENTS unit_test_framework)
add_executable(example "main.cpp")
target_link_libraries(example Boost::unit_test_framework)
---
main.cpp
#define BOOST_TEST_MODULE MyTest
#include
Dennis Luehring wrote: ...
the clang-cl build got a link error: lld-link: error: could not open 'libboost_unit_test_framework-clangw14-mt-gd-x64-1_79.lib': no such file or directory even when boost is built with -layout=tagged
This error is caused by autolinking. The CMake config files used to define BOOST_ALL_NO_LIB, which disabled autolinking entirely, but this caused complaints (as autolinking is useful when it works correctly), so we changed the config files to only define the appropriate BOOST_<LIBNAME>_NO_LIB macro. This fails in the specific case of Boost.Test because there the macro name used presently to disable autolink is BOOST_TEST_NO_LIB, but the CMake config for Boost::unit_test_framework defines BOOST_UNIT_TEST_FRAMEWORK_NO_LIB (as it derives the macro by uppercasing the library name.) We've changed Boost.Test to recognize the _DYN_LINK macros corresponding to the library name: https://github.com/boostorg/test/commit/625bafd2cdc3e9a6f338573a17558050e2bd... but didn't think at the time to do the same for the _NO_LIB ones (as it was unnecessary then). We should fix this in Boost.Test. In the meantime, you can disable autolinking by defining BOOST_ALL_NO_LIB, which can be done e.g. by changing
target_link_libraries(example Boost::unit_test_framework)
to target_link_libraries(example Boost::unit_test_framework Boost::disable_autolinking)
Am 04.06.2022 um 12:57 schrieb Peter Dimov via Boost:
We should fix this in Boost.Test. In the meantime, you can disable autolinking by defining BOOST_ALL_NO_LIB, which can be done e.g. by changing
target_link_libraries(example Boost::unit_test_framework) to
target_link_libraries(example Boost::unit_test_framework Boost::disable_autolinking)
thanks - that tips fixes it for my small example and my big project any idea how to build boost with clang-cl, or is that just not supported?
Dennis Luehring wrote:
Am 04.06.2022 um 12:57 schrieb Peter Dimov via Boost:
We should fix this in Boost.Test. In the meantime, you can disable autolinking by defining BOOST_ALL_NO_LIB, which can be done e.g. by changing
target_link_libraries(example Boost::unit_test_framework) to
target_link_libraries(example Boost::unit_test_framework Boost::disable_autolinking)
thanks - that tips fixes it for my small example and my big project
any idea how to build boost with clang-cl, or is that just not supported?
Not without more information about the errors you are getting. I just tried a build on the master branch with `b2 toolset=clang`. I'm using the Clang from my VS2022 installation, and have the following in my user-config.jam: using clang-win : : "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\Llvm\\x64\\bin\\clang-cl.exe" : <manifest-tool>"\"C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.19041.0\\x64\\mt.exe\"" ; Configuring the manifest tool can be avoided by using `embed-manifest-via=linker` on the command line. Everything seems to build fine for me with the exception of "graph_parallel", which gives a bunch of compile and link errors. I doubt you have that enabled though, as it requires MPI.
Am 05.06.2022 um 11:58 schrieb Peter Dimov via Boost:
Everything seems to build fine for me with the exception of "graph_parallel", which gives a bunch of compile and link errors. I doubt you have that enabled though, as it requires MPI.
your user-config.jam works for me, thanks Boost::disable_autolinking is not needed anymore using this clang-win build of boost the example im doing just uses the unit test framework - my real project some more libraries, but i'll test them later
participants (2)
-
Dennis Luehring
-
Peter Dimov