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

Alexander Korsunsky fat.lobyte9 at gmail.com
Tue Mar 13 16:47:27 PDT 2012


On 2012-03-01 12:03, David Chisnall wrote:
> On 1 Mar 2012, at 10:03, Alexander Korsunsky wrote:
> 
>> With the "--stdlib=libc++" option, the linking of the program fails,
>> asking for some symbols from the CXXABI:
>>
>> What did I do wrong? Is Clang or libcxx misconfigured, or is this a
>> compiler bug? How could I fix or work around the issue?
> 
> libc++ does not provide the ABI layer, just the STL layer.  You need another library for the ABI.  You may be able to link to libstdc++ and get libsupc++ indirectly.  Alternatively, try using libcxxrt:
> 

Ok, I finally figured out how get a working standard library, using
libc++, libc++abi and libunwind. This is how I did it:

1. Download libunwind from here:
http://www.nongnu.org/libunwind/download.html and unpack it.

2. Download libc++abi from here: http://libcxxabi.llvm.org/
Go into the lib directory, and trick the build script into using the
libunwind/include directory, for example with the CPATH environment
variable. Compile libc++abi with the build script and (manually) install
the resulting libraries.

3. Download libc++ from here: http://libcxx.llvm.org/
Configure it to link against libc++abi by adding the "-lc++abi" flag to
the CMake variable "CMAKE_SHARED_LINKER_FLAGS".
Build libc++.
Add the libcxxabi/include directory to the include directories, for
example by adding "-I/path/to/libcxxabi/include" to the Cmake variable
"CMAKE_CXX_FLAGS".
Compile libc++

Now I had a more or less working standard library. One issue remains: I
have to manually add "-lc++abi" to every compiler invocation, because
this libary is not linked by default.



Ok, here comes suggestion time:

1) Maybe I didn't go the optimal way, but to me it seemed pretty darn
hard to get the compiler working.
Although Clang and libc++ and libc++abi are different projects, it would
be really nice if one didn't have to go through setting them up and
compiling manually.
Once libc++/libc++abi reach a good level of maturity they should be
integrated into (or at least shipped with) Clang.

A "drop in"-replacement for GCC was not possible, because the libstdc++
headers caused compile errors, so libc++ had to be used.

2) Please solve the thingy with the missing <unwind.h> on linux:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-February/019906.html

3) Please add a flag to link with the right library "-lc++abi" to the
linker command line in the compiler driver, if "-stdlib=libc++" was
specified. Maybe it is possible to check the dependencies of libc++
(like ldd?), and add the correct library to the command line.

I think this concerns tools/clang/lib/Driver/Tools.cpp around line 4700.

4) Please, oh please document libc++ and libc++abi properly. It was a
nice guessing game of how to properly build/install the stuff or which
dependencies to use.


That being said, I really look forward to your compiler being more
adopted in the Linux and Windows world. Diagnostics are a lot better,
and the whole project looks a lot cleaner/saner than GCC. Even
C++11-Support caught up!

Please keep up the good work and thanks for what you already achieved!

Regards, Alexander



More information about the cfe-dev mailing list