Reputation: 36111
After spending almost an hour on filtering output of
clang -v hello_world.c
I got the following linking command:
ld -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 \
/usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o \
hello_world.o /usr/lib/x86_64-linux-gnu/libc.so \
/usr/lib/x86_64-linux-gnu/crtn.o
Is there an easier way to find out that -lc
will expand to /usr/lib/x86_64-linux-gnu/libc.so
?
I need to know which files are used so I can copy them to another system for cross compiling.
edit
Looks like I should use the cross-compile toolchain. From clang docs:
https://clang.llvm.org/docs/CrossCompilation.html
When you have extracted your cross-compiler from a zip file into a directory, you have to use --sysroot=. The path is the root directory where you have unpacked your file, and Clang will look for the directories bin, lib, include in there.
Where can I get that zip file they refer to? I'm interested in x86_64-linux-gnu
target.
Upvotes: 2
Views: 569
Reputation: 4287
This will list all the files linked to libc.so.6
:
for i in `find . -type f -executable`
do
j=$(ldd $i | grep libc.so.6 | wc -l)
if [ $j -gt 0 ]
then
echo $i
fi
done
In case you want to find out what the path of libc.so.6
is, stated in the original question something similar to:
ldd `which ld` | sed 's/^[[:space:]]libc.so.6[[:space:]]=>[[:space:]]\(.*\)[[:space:]](.*)/\1/p' | grep --color=never libc.so
will type the path, you can obviously replace the expression after ldd with any filename.
From the comments, there is a way with clang directly though it will generate a lot of noise which is significantly harder to exclude compared to the ldd way.
clang -Wl,--verbose hello_world.c
will tell the linker to be verbose and it will eventually tell you all the library paths tried for each library.
Upvotes: 2