[cfe-dev] Clang 3.1: Can't link Hello World-program program on Linux
David Chisnall
csdavec at swan.ac.uk
Sat Mar 3 07:16:03 PST 2012
On 3 Mar 2012, at 14:02, bruce.r.stephens at gmail.com wrote:
> 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.
In FreeBSD trunk, we have libc++.so dynamically linked against libcxxrt.so (so that eventually we can link libstdc++.so against it and - with some care - mix libraries linked against both. It hasn't been extensively tested, but compiling things with -stdlib=libc++ seems to work without needing any extra flags.
David
More information about the cfe-dev
mailing list