Short question:
How does llvm-ld locate libstdc++?
Details:
I am getting the following error message:
llvm-ld: error: Cannot find library 'stdc++'
while running llvm-ld. I am trying to understand how llvm-ld searches for libstdc++.
I am setting up a new system and following compilation steps that work on a different system. Eventually I noticed a difference with the LD_LIBRARY_PATH that was set in my .bashrc on the old system that included a large number of directories including for Cadence and other miscellaneous software. I don’t want to use the LD_LIBRARY_PATH, I want to be able to link against libstdc++ by supplying the appropriate command line parameters to llvm-ld.
The command I am running is:
llvm-ld -disable-internalize -native -o foo foo.bc4 -L/usr/lib/x86_64-linux-gnu -lpthread -lrt -lstdc++ -lm -v
which results in the following output:
Linking bitcode file 'foo.bc4'
Linked in file 'foo.bc4'
Linking archive file '/usr/lib/x86_64-linux-gnu/libpthread.a'
Linking archive file '/usr/lib/x86_64-linux-gnu/librt.a'
llvm-ld: error: Cannot find library 'stdc++'
However running ls -l /usr/lib/x86_64-linux-gnu/libstdc++* results in:
lrwxrwxrwx 1 root root 19 Apr 15 16:34 /usr/lib/x86_64-linux-gnu/libstdc++.so.6 -> libstdc++.so.6.0.16
-rw-r--r-- 1 root root 962656 Apr 15 16:36 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
So I don’t understand why llvm-ld is not finding this file? Especially since when I compile with with the LD_LIBRARY_PATH set and then run ldd on the resulting executable I get the following output:
linux-vdso.so.1 => (0x00007ffff7ffe000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ffff7dc1000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ffff7ac0000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ffff77c6000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ffff75b0000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffff71f0000)
/lib64/ld-linux-x86-64.so.2 (0x0000555555554000)
Which seems to indicate that the version of libstdc++ that I want is /usr/lib/x86_64-linux-gnu/libstdc++.so.6 but I can’t figure out why llvm-ld is not locating it with the search path -L/usr/lib/x86_64-linux-gnu.
For reference: uname -a results in: Linux FOO 3.2.0-30-generic #48-Ubuntu SMP Fri Aug 24 16:52:48 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
And llvm-ld --version:
LLVM (http://llvm.org/):
LLVM version 3.1svn
Optimized build.
Built Sep 14 2012 (13:22:38).
Default target: x86_64-unknown-linux-gnu
Host CPU: core2
It looks like
llvm-ldisn’t looking for.so.#. According to themanpage:You can make this work by creating a symlink
/usr/lib/x86_64-linux-gnu/libstdc++.so->libstdc++.so.6.I usually link with
clangdirectly, since it understands searching for C++ library things better.