C Building clang from source

Hi

Solved the problem: I needed tp ise CMAKE_SHARED_LINKER_FLAGS (which I set to -Wl,-rpath,$ORIGIN/.)

Original post:

I just had a go at building clang trunk from svn (I want to have a go with the C++1z features). All seemed to go well except that after install, the executables can't find libc++abi.so:

Code:
$ ./tools/clang/bin/clang --version
Shared object "libc++abi.so.1" not found, required by "libc++.so.1"

My cmake command:

Code:
$ cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/home/paulf/tools/clang -DCMAKE_BUILD_TYPE=Release /usr/home/paulf/scratch/clang/llvm

I tried rebuilding again with LD_RUN_PATH set to/home/paulf/tools/clang/lib (where libc++abi.so.1 will get installed) but this made no difference. I also tried configuring with -DCMAKE_EXE_LINKER_FLAGS=-Wl,-rpath,/home/paulf/tools/clang/lib but again it made no difference.

Any idea why LD_RUN_PATH and CMAKE_EXE_LINKER_FLAGS aren't being respected?

Other than than using LD_LIBRARY_PATH is there a clean way to get this to work?

Update2:
clang and the executables do have the right rpath:

Code:
readelf -d bin/clang | grep path
 0x000000000000000f RPATH                Library rpath: [/home/paulf/tools/clang/lib:$ORIGIN/../lib]
 0x000000000000001d RUNPATH              Library runpath: [/home/paulf/tools/clang/lib:$ORIGIN/../lib]

ldd and the link loader still aren't happy:

Code:
ldd bin/clang
bin/clang:
        libthr.so.3 => /lib/libthr.so.3 (0x803dc1000)
        librt.so.1 => /usr/lib/librt.so.1 (0x803fe8000)
        libncurses.so.8 => /lib/libncurses.so.8 (0x8041ed000)
        libz.so.6 => /lib/libz.so.6 (0x804441000)
        libm.so.5 => /lib/libm.so.5 (0x804658000)
        libc++.so.1 => /home/paulf/tools/clang/lib/libc++.so.1 (0x804883000)
        libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x804b48000)
        libc.so.7 => /lib/libc.so.7 (0x804d66000)
        libc++abi.so.1 => not found (0)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x80511a000)

The problem is that rpath is not transitive. So when libc++.so.1 gets loaded with the rpath of clang, it has a dependency on libc++abi.so.1. Loading this doesn't use the rpath of clang, it uses the rpath of libc++.so.1.

Which is:
In the build directory:

Code:
readelf -d lib/libc++.so.1.0 | grep path
 0x000000000000000f RPATH                Library rpath: [/usr/local/lib:/home/paulf/scratch/clang/llvm/build/lib:]
 0x000000000000001d RUNPATH              Library runpath: [/usr/local/lib:/home/paulf/scratch/clang/llvm/build/lib:]

And in the install directory:
Code:
readelf -d lib/libc++.so.1.0 | grep path
[nothing]

Hmm. I also see that the system clang is statically linked. One way to get around broken dynamic library dependencies I suppose.

A+
Paul
 
Back
Top