Boost logo

Boost Users :

Subject: [Boost-users] How to build Boost with Clang/libc++ and NOT link against libstdc++?
From: Deniz Bahadir (deniz.bahadir_at_[hidden])
Date: 2017-01-20 04:13:56


Hi guys,

I am struggling with building the Boost (1.58.0) libraries with Clang
(3.8) and libc++ (on Ubuntu 16.04).

I am able to build the Boost libraries using Clang and flags "-std=c++14
-stdlib=libc++", however, I noticed that several libraries are still
linked against GCC's standard-library "libstdc++".

I then tried adding the flag "-lc++abi" (later I tried "-Wl,-lc++abi")
to Boost.Build options "cxxflags" and "linkflags" to explicitly link
against "libc++abi". With no luck. Several boost-libraries are still
linked against "libstdc++".

Does anyone know how and why this link-dependency gets added and how to
get rid of them? Does it come in through some other link-dependencies?
At least none of them seem to link to "libstdc++"?

The Boost shared-libraries that link to "libstdc++" are:

libboost_chrono-clang38-mt-1_58_0.so.1.58.0
libboost_context-clang38-mt-1_58_0.so.1.58.0
libboost_coroutine-clang38-mt-1_58_0.so.1.58.0
libboost_date_time-clang38-mt-1_58_0.so.1.58.0
libboost_filesystem-clang38-mt-1_58_0.so.1.58.0
libboost_graph-clang38-mt-1_58_1.so.0.58.0
libboost_iostreams-clang38-mt-1_58_0.so.1.58.0
libboost_locale-clang38-mt-1_58_0.so.1.58.0
libboost_log-clang38-mt-1_58_0.so.1.58.0
libboost_log_setup-clang38-mt-1_58_0.so.1.58.0
libboost_math_tr1-clang38-mt-1_58_0.so.1.58.0
libboost_math_tr1f-clang38-mt-1_58_0.so.1.58.0
libboost_math_tr1l-clang38-mt-1_58_0.so.1.58.0
libboost_program_options-clang38-mt-1_58_0.so.1.58.0
libboost_python-clang38-mt-1_58_0.so.1.58.0
libboost_random-clang38-mt-1_58_0.so.1.58.0
libboost_regex-clang38-mt-1_58_0.so.1.58.0
libboost_signals-clang38-mt-1_58_0.so.1.58.0
libboost_thread-clang38-mt-1_58_0.so.1.58.0
libboost_timer-clang38-mt-1_58_0.so.1.58.0
libboost_unit_test_framework-clang38-mt-1_58_0.so.1.58.0
libboost_wave-clang38-mt-1_58_0.so.1.58.0

The once that are fine and do not link against "libstdc++" are:

libboost_atomic-clang38-mt-1_58_0.so.1.58.0
libboost_container-clang38-mt-1_58_0.so.1.58.0
libboost_math_c99-clang38-mt-1_58_0.so.1.58.0
libboost_math_c99f-clang38-mt-1_58_0.so.1.58.0
libboost_math_c99l-clang38-mt-1_58_0.so.1.58.0
libboost_serialization-clang38-mt-1_58_0.so.1.58.0
libboost_system-clang38-mt-1_58_0.so.1.58.0
libboost_wserialization-clang38-mt-1_58_0.so.1.58.0

Interestingly, all libraries are also linked against "libc++abi" except for:

libboost_atomic-clang38-mt-1_58_0.so.1.58.0
libboost_container-clang38-mt-1_58_0.so.1.5

For completeness, my build-command is this:

cd /home/jenkins/workspace/Pipeline_Boost/sources/boost_1_58_0

LINK_LIBCXXABI="-Wl,-lc++abi"
COMMON_COMPILER_FLAGS="-m64 -fpic -fdiagnostics-color=always -O3"
CFLAGS="$COMMON_COMPILER_FLAGS"
CXXFLAGS="$COMMON_COMPILER_FLAGS -std=c++14 -stdlib=libc++
-isystem/usr/include/libcxxabi $LINK_LIBCXXABI"
CC=/usr/bin/clang-3.8
CXX=/usr/bin/clang++-3.8

/home/jenkins/workspace/Pipeline_Boost_at_3/clang38/build/boost-build/b2
     -j1 -q \
 
--build-dir=/home/jenkins/workspace/Pipeline_Boost_at_3/clang38/build/boost \
     --build-type=minimal --layout=versioned address-model=64 install \
 
--prefix=/home/jenkins/workspace/Pipeline_Boost_at_3/clang38/installed/opt/BENOCS/clang38
  \
 
--libdir=/home/jenkins/workspace/Pipeline_Boost_at_3/clang38/installed/opt/BENOCS/clang38/lib/x86_64-linux-gnu
  \
     dll-path==/opt/BENOCS/clang38/lib/x86_64-linux-gnu \
     toolset=clang-3.8 \
     cflags="$CFLAGS" CXXFLAGS="$CXXFLAGS" \
     linkflags="-Wl,--as-needed $LINK_LIBCXXABI"

For the environment-variable LINK_LIBCXXABI I tried "-lc++abi" as well
and also tried providing it only in the cxxflags or the linkflags or
both (as above).

I would be happy, if anyone could explain that behavior or could even
provide a workaround/fix for me, so that "libstdc++" is no longer linked.

Thanks,
Deniz

PS: BTW, does anyone know if it is correct, that shared libraries (in
general) that are linked against "libc++abi" do always also link to
"libgcc_s"? (What is it for?)

-- 
BENOCS GmbH
Dipl.-Inform. Deniz Bahadir
Winterfeldtstr. 21
10781 Berlin
Germany
Phone: +49 - 30 / 577 0004-22
Email: deniz.bahadir_at_[hidden]
www.benocs.com
Board of Management:
   Michael Wolz, Dr.-Ing. Oliver Holschke, Dr.-Ing. Ingmar Poese
Commercial Register: Amtsgericht Bonn HRB 19378

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net