Discussion:
[Boost-users] How to build Boost with Clang/libc++ and NOT link against libstdc++?
Deniz Bahadir
2017-01-20 09:13:56 UTC
Permalink
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/***@3/clang38/build/boost-build/b2
-j1 -q \

--build-dir=/home/jenkins/workspace/***@3/clang38/build/boost \
--build-type=minimal --layout=versioned address-model=64 install \

--prefix=/home/jenkins/workspace/***@3/clang38/installed/opt/BENOCS/clang38
\

--libdir=/home/jenkins/workspace/***@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: ***@benocs.com
www.benocs.com

Board of Management:
Michael Wolz, Dr.-Ing. Oliver Holschke, Dr.-Ing. Ingmar Poese
Commercial Register: Amtsgericht Bonn HRB 19378
Jürgen Hunold
2017-01-20 11:40:48 UTC
Permalink
Hi Deniz,
Post by Deniz Bahadir
Hi guys,
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++".
This works for me for quite a while. Please make sure you rebuild all
libraries. Hint: b2 does not cache compiler flags. Add "-a" to your command
line to force a full rebuild.
Post by Deniz Bahadir
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++"?
Most probably a not clean rebuild.
Post by Deniz Bahadir
dll-path==/opt/BENOCS/clang38/lib/x86_64-linux-gnu \
toolset=clang-3.8 \
The toolset "clang-3.8" is configured where and how?
Post by Deniz Bahadir
cflags="$CFLAGS" CXXFLAGS="$CXXFLAGS" \
cxxflags="$CXXFLAGS"
Post by Deniz Bahadir
linkflags="-Wl,--as-needed $LINK_LIBCXXABI"
I'd put the extra flags into user-/project-/site-config.jam.
Post by Deniz Bahadir
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).
linkflags should contain "-stdlib=libc++", too
Post by Deniz Bahadir
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.
from my user-config.jam:

# Clang trunk
using clang : # version
: # compiler
$(HOME)/local/bin/clang++
: # options
<cxxflags>-stdlib=libc++
<cxxflags>-I$(HOME)/local/include/c++/v1
<linkflags>-stdlib=libc++
<linkflags>-L$(HOME)/local/lib
;

with custom clang trunk installed to $(HOME)/local
Post by Deniz Bahadir
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?)
The basic compiler runtime AFAIK. Might be replaced by clang's compiler-rt, I
guess. But that is off-topic

Yours,

Jürgen
--
* Dipl.-Math. Jürgen Hunold !
* voice: ++49 4257 300 ! Fährstraße 1
* fax : ++49 4257 300 ! 31609 Balge/Sebbenhausen
* ***@gmx.eu ! Germany
Deniz Bahadir
2017-01-20 13:26:07 UTC
Permalink
Hi Jürgen,

thanks for your answer.
Post by Jürgen Hunold
Hi Deniz,
Post by Deniz Bahadir
Hi guys,
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++".
This works for me for quite a while. Please make sure you rebuild all
libraries. Hint: b2 does not cache compiler flags. Add "-a" to your command
line to force a full rebuild.
[...]
Most probably a not clean rebuild.
I built the libraries using our build-server which made sure to use an
entirely new build- and source-directory. So that should not be the
problem in my case.
Post by Jürgen Hunold
Post by Deniz Bahadir
dll-path==/opt/BENOCS/clang38/lib/x86_64-linux-gnu \
toolset=clang-3.8 \
The toolset "clang-3.8" is configured where and how?
I cannot really tell. At least it works. It uses the correct
clang-executable.
Post by Jürgen Hunold
Post by Deniz Bahadir
cflags="$CFLAGS" CXXFLAGS="$CXXFLAGS" \
cxxflags="$CXXFLAGS"
Yes, you are right. However, that error just went in when writing this
email. The build-server used the correct command.
Post by Jürgen Hunold
Post by Deniz Bahadir
linkflags="-Wl,--as-needed $LINK_LIBCXXABI"
I'd put the extra flags into user-/project-/site-config.jam.
I am not so fond of using these. I always get confused how they work,
where they have to be located and to what project it applies.
Especially, as our build-server builds boost with several compilers with
(possibly) different settings.
Post by Jürgen Hunold
Post by Deniz Bahadir
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).
linkflags should contain "-stdlib=libc++", too
I think, that did the trick. :-)
It no longer links against "libstdc++".
Post by Jürgen Hunold
[...]
Post by Deniz Bahadir
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?)
The basic compiler runtime AFAIK. Might be replaced by clang's compiler-rt, I
guess. But that is off-topic
Thanks for this additional insight.
Post by Jürgen Hunold
Yours,
Jürgen
Thanks a lot,
Deniz
--
BENOCS GmbH
Dipl.-Inform. Deniz Bahadir
Winterfeldtstr. 21
10781 Berlin
Germany
Phone: +49 - 30 / 577 0004-22
Email: ***@benocs.com
www.benocs.com

Board of Management:
Michael Wolz, Dr.-Ing. Oliver Holschke, Dr.-Ing. Ingmar Poese
Commercial Register: Amtsgericht Bonn HRB 19378
Loading...