Boost logo

Boost :

Subject: [boost] Failing to use b2/bjam including libraries with Clang
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2018-03-30 14:37:42


I am still failing to get Clang on Windows 10 to work with b2/bjam *linking to libraries*.

I have a few simple test cases, using Boost.System to display an error code ,using Boost.Test for a 'hello World" use of Boost.Test,
and a simple regex example1 linking to Boost.Regex library.

All links to libraries are static (to avoid reported problems with DLL and Clang).

I have tried to use the LLD linker http://releases.llvm.org/6.0.0/tools/lld/docs/ReleaseNotes.html
as some have recommended this, but not successfully with libraries, so far.

Things that DO work OK with Clang 6.0.0 are

1 Visual Studio IDE (using Boost prebuilt libraries) Platform Toolset = llvm-2014 and MS linker only.

2 Codeblocks IDE (mingw64 on windows 10) (using normal Boost prebuilt libraries as part of the normal install) and clang++.exe.
(But NOT when using the LTO lld.exe linker getting

  error: Expected a single module

 ???- but I am not trying to use C++ modules!).

3 Using b2/bjam to run a *single* exe (no libraries).

jamfile is just [ run hello_boost.cpp ] with >b2 toolset=gcc-7.2.0,msvc-14.1,clang-6.0.0

4 Using all examples in jamfile b2/bjam with libraries with toolset=gcc-7.2.0,msvc-14.1 (so I am confident that it is not a problem
with the C++ or the jamfile).

What *doesn't work* is b2/bjam using a library with toolset=clang-6.0.0,
neither using clang++ linker nor using LTO llvm-lld.exe.

And since I want to write

  b2 -a -j6 --debug-configuration -d2 toolset=msvc-14.1,gcc-7.2.0,clang-6.0.0 address-model=64 > my.log

this is most disappointing :-(

My user-config.jam contains

using clang
  : # Version.
    6.0.0
  : # Location of Clang compiler .exe file(s).
    "C:/LLVM/clang-600/LLVM/bin/clang++.exe"
  : # Options.
    <compileflags>-v
    <compileflags>-m64
    <compileflags>-fmsc-version=1900
    <compileflags>--target=i686-pc-windows-msvc
    <define>_CRT_SECURE_NO_DEPRECATE
    <define>_CRT_SECURE_NO_WARNINGS
    <cxxflags>-std=c++17
    <cxxflags>-flto=thin <<<<<<< if trying to use LTO lld linker
    <cxxflags>-Wno-deprecated
    <cxxflags>-Wno-deprecated-declarations

    <linkflags>-v
    <linkflags>-fuse-ld=lld <<<<<<< if trying to use LTO lld linker
    <linkflags>-flto=thin <<<<<<< if trying to use LTO lld linker
    <linkflags>--verbose
    <linkflags>-m64
    <linkflags>--target=i686-pc-windows-msvc
    <linkflags>-lmsvcrt

The Boost.Test and Boost.System libraries are built as expected (for Clang) at

"..\..\..\bin.v2\libs\system\build\clang-gnu-linux-6.0.0\release\address-model-64\link-static\threadapi-win32\libboost_system-clang6
0-x64-1_66.lib"

my jamfile contains lines like

  [ run hello_boost_system.cpp ../../system/build//boost_system/<link>static ]

  [ run hello_boost_test.cpp : : : <library>/boost/test//boost_unit_test_framework/<link>static ]

After trying a bewildering array of linkers, and many options, I finally always end up with a series of link failures with errors
either like

   error: lto.tmp: undefined symbol: ? system_category_at_system@boost@@YAAEBVerror_category_at_12@XZ

or a missing entry point:

  LINK : fatal error LNK1561: entry point must be defined
  (This appears to be a message from MSVC, not the lld linker?)

clang-linux.link
..\..\..\bin.v2\libs\hello_boost_test\test\hello_boost_system.test\clang-gnu-linux-6.0.0\release\address-model-64\threadapi-win32\he
llo_boost_system.exe

    "C:/LLVM/clang-600/LLVM/bin/clang++.exe" -o
"..\..\..\bin.v2\libs\hello_boost_test\test\hello_boost_system.test\clang-gnu-linux-6.0.0\release\address-model-64\threadapi-win32\h
ello_boost_system.exe" -Wl,--start-group
"..\..\..\bin.v2\libs\hello_boost_test\test\hello_boost_system.test\clang-gnu-linux-6.0.0\release\address-model-64\threadapi-win32\h
ello_boost_system.obj"
"..\..\..\bin.v2\libs\system\build\clang-gnu-linux-6.0.0\release\address-model-64\link-static\threadapi-win32\libboost_system-clang6
0-x64-1_66.lib" -Wl,-Bstatic -Wl,-Bdynamic -Wl,--end-group -v -fuse-ld=lld -flto=thin --verbose -m64
--target=i686-pc-windows-msvc -lmsvcrt -m64

clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\LLVM\clang-600\LLVM\bin
 "C:\\LLVM\\clang-600\\LLVM\\bin\\lld-link"
"-out:..\\..\\..\\bin.v2\\libs\\hello_boost_test\\test\\hello_boost_system.test\\clang-gnu-linux-6.0.0\\release\\address-model-64\\t
hreadapi-win32\\hello_boost_system.exe" -defaultlib:libcmt "-libpath:C:\\Program Files (x86)\\Microsoft Visual
Studio\\2017\\Professional\\VC\\Tools\\MSVC\\14.13.26128\\lib\\x64" "-libpath:C:\\Program Files (x86)\\Windows
Kits\\10\\Lib\\10.0.16299.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.16299.0\\um\\x64" -nologo
--start-group
"..\\..\\..\\bin.v2\\libs\\hello_boost_test\\test\\hello_boost_system.test\\clang-gnu-linux-6.0.0\\release\\address-model-64\\thread
api-win32\\hello_boost_system.obj"
"..\\..\\..\\bin.v2\\libs\\system\\build\\clang-gnu-linux-6.0.0\\release\\address-model-64\\link-static\\threadapi-win32\\libboost_s
ystem-clang60-x64-1_66.lib" -Bstatic -Bdynamic --end-group msvcrt.lib
C:\LLVM\clang-600\LLVM\bin\lld-link: warning: ignoring unknown argument: --start-group
C:\LLVM\clang-600\LLVM\bin\lld-link: warning: ignoring unknown argument: -Bstatic
C:\LLVM\clang-600\LLVM\bin\lld-link: warning: ignoring unknown argument: -Bdynamic
C:\LLVM\clang-600\LLVM\bin\lld-link: warning: ignoring unknown argument: --end-group
C:\LLVM\clang-600\LLVM\bin\lld-link: error: lto.tmp: undefined symbol: ?system_category_at_system@boost@@YAAEBVerror_category_at_12@XZ
C:\LLVM\clang-600\LLVM\bin\lld-link: error: lto.tmp: undefined symbol: ?generic_category_at_system@boost@@YAAEBVerror_category_at_12@XZ
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

Which seems to indicate some link problem finding error_category
(error_category is found OK with GCC or MSVC)?

and for a simple use of Boost.Test library

clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\LLVM\clang-600\LLVM\bin
 "C:\\LLVM\\clang-600\\LLVM\\bin\\lld-link"
"-out:..\\..\\..\\bin.v2\\libs\\hello_boost_test\\test\\hello_boost_test.test\\clang-gnu-linux-6.0.0\\release\\address-model-64\\thr
eadapi-win32\\hello_boost_test.exe" -defaultlib:libcmt "-libpath:C:\\Program Files (x86)\\Microsoft Visual
Studio\\2017\\Professional\\VC\\Tools\\MSVC\\14.13.26128\\lib\\x64" "-libpath:C:\\Program Files (x86)\\Windows
Kits\\10\\Lib\\10.0.16299.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.16299.0\\um\\x64" -nologo
--start-group
"..\\..\\..\\bin.v2\\libs\\hello_boost_test\\test\\hello_boost_test.test\\clang-gnu-linux-6.0.0\\release\\address-model-64\\threadap
i-win32\\hello_boost_test.obj"
"..\\..\\..\\bin.v2\\libs\\test\\build\\clang-gnu-linux-6.0.0\\release\\address-model-64\\link-static\\threadapi-win32\\libboost_uni
t_test_framework-clang60-x64-1_66.lib"
"..\\..\\..\\bin.v2\\libs\\timer\\build\\clang-gnu-linux-6.0.0\\release\\address-model-64\\link-static\\threadapi-win32\\libboost_ti
mer-clang60-x64-1_66.lib"
"..\\..\\..\\bin.v2\\libs\\chrono\\build\\clang-gnu-linux-6.0.0\\release\\address-model-64\\link-static\\threadapi-win32\\libboost_c
hrono-clang60-x64-1_66.lib"
"..\\..\\..\\bin.v2\\libs\\system\\build\\clang-gnu-linux-6.0.0\\release\\address-model-64\\link-static\\threadapi-win32\\libboost_s
ystem-clang60-x64-1_66.lib" -Bstatic -Bdynamic --end-group msvcrt.lib
C:\LLVM\clang-600\LLVM\bin\lld-link: warning: ignoring unknown argument: --start-group
C:\LLVM\clang-600\LLVM\bin\lld-link: warning: ignoring unknown argument: -Bstatic
C:\LLVM\clang-600\LLVM\bin\lld-link: warning: ignoring unknown argument: -Bdynamic
C:\LLVM\clang-600\LLVM\bin\lld-link: warning: ignoring unknown argument: --end-group
C:\LLVM\clang-600\LLVM\bin\lld-link: error: entry point must be defined
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

Which leaves me baffled.

Verbose logs are attached, and I have several others if any kind soul would be willing to pass a more expert eye over them.

Ideas on what I am doing wrong most welcome?

Thanks.

Paul

PS I am away for a while, but eagerly await solutions on my return ;-)

---
Paul A. Bristow
Prizet Farmhouse
Kendal UK LA8 8AB
+44 (0) 1539 561830





Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk