[cfe-dev] Clang 3.1: Can't link Hello World-program program on Linux

bruce.r.stephens at gmail.com bruce.r.stephens at gmail.com
Sat Mar 3 06:02:47 PST 2012


Alexander Korsunsky
<fat.lobyte9-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> writes:

> On 2012-03-02 10:44, David Chisnall wrote:

[...]

>> You shouldn't need to do this, just link libc++ against libcxxrt (which should link against libdl on Linux).
>
> How do I do this?
>
> When I add "-lcxxrt" or "-l:libcxxrt.a" to the linker command line of
> libc++, the linking of libc++ succeeds.
> But then, when compiling helloworld, symbols are missing unless I
> excplitly specify '-lcxxrt'.
> Shouldn't linking libc++ against libcxxrt pull that in automatically?

Really? It worked for me, after a few stumbles. I needed to build
libcxxrt with clang and clang++ adding -fPIC to C_FLAGS and CXX_FLAGS
(otherwise libcxxrt.a isn't suitable for linking into the shared
libc++).

Then I built libc++, adding -DLIBCXXRT to EXTRA_FLAGS and libcxxrt.a to
the link line. Then at least a Hello World seems to work, and the
executable doesn't drag in libstdc++.

I had to create a link to libc++.so.1 from /usr/lib (I installed it into
/usr/local/lib, but that doesn't seem to be searched, even though clang
is in /usr/local/bin), and the headers have to be in
/usr/local/lib/clang/3.1. If you don't get the headers in the right
place your clang may pick up g++ headers and that'll cause problems.

[...]




More information about the cfe-dev mailing list