[boost] how to build boost 1.79 with "clang-cl" under Windows?

978 views
Skip to first unread message

Dennis Luehring via Boost

unread,
Jun 4, 2022, 2:56:24 AM6/4/22
to bo...@lists.boost.org, Dennis Luehring
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-error-lnk1107?view=msvc-170)


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















_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Dennis Luehring via Boost

unread,
Jun 4, 2022, 4:51:10 AM6/4/22
to bo...@lists.boost.org, Dennis Luehring
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 <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE( my_test )
{
  BOOST_CHECK( true );
}

---

how to build

my build environment LLVM 14, cmake 3.23, VS2017 latest, Boost 1.79

build boost 1.79 with VS2017
  1. boostrap.bat
  2. b2 -j%NUMBER_OF_PROCESSORS% toolset=msvc-14.1 address-model=64
--stagedir=.\lib64-msvc-14.1 --build-dir=.\__build --build-type=complete
threading=multi architecture=x86 --with-test

build example on console:
  1. set my_ninja_dir=D:/temp/clang_cl_test/ninja-win
  2. set my_llvm_dir=C:/Program Files/LLVM/bin
  3. set my_boost_dir=D:/temp/clang_cl_test/boost_1_79_0/lib64-msvc-14.1
  4. set path=%path%;%my_ninja_dir%;%my_llvm_dir%
  5. "C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
  VS2017/cl build:
    6. cmake -G Ninja -DCMAKE_PREFIX_PATH="%my_boost_dir%"
-DCMAKE_BUILD_TYPE="Debug" ..\example
  clang-cl build:
    6. cmake -G Ninja -DCMAKE_C_COMPILER="clang-cl.exe"
-DCMAKE_CXX_COMPILER="clang-cl.exe" -DBoost_COMPILER="vc141"
-DCMAKE_PREFIX_PATH="%my_boost_dir%" ..\example
  7. ninja

the VS2017/cl builds and the example exe works

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

Peter Dimov via Boost

unread,
Jun 4, 2022, 6:57:43 AM6/4/22
to bo...@lists.boost.org, Peter Dimov
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/625bafd2cdc3e9a6f338573a17558050e2bd0e58

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)

Dennis Luehring via Boost

unread,
Jun 5, 2022, 2:57:23 AM6/5/22
to bo...@lists.boost.org, Dennis Luehring
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?

Peter Dimov via Boost

unread,
Jun 5, 2022, 5:58:25 AM6/5/22
to bo...@lists.boost.org, Peter Dimov
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.

Dennis Luehring via Boost

unread,
Jun 5, 2022, 12:15:35 PM6/5/22
to bo...@lists.boost.org, Dennis Luehring
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
Reply all
Reply to author
Forward
0 new messages