views:

33

answers:

2

How to I find the filename of a library via the library name?

In otherwords, when I use "-lc", I know it is /lib/libc.so.6 (or something similar.) I want to be able to type some command where "-lc" is the input and "/lib/libc.so.6" is the output. To extend this idea futher, I wanted to specify my own search path so I can use this library resolver for different toolchains... Any help would be awesome,

Thanks Chenz

+1  A: 

gcc -Wl,--trace file.c

will print list of input files for ld

gonzo
+1  A: 

If you want to find out where a given GCC will find libc.a or libc.so, do this:

gcc --print-file-name=libc.a
gcc --print-file-name=libc.so

The reason -lc translates into libc.so.6 is somewhat complicated: for glibc, libc.so is a linker script, which usually contains:

/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */
OUTPUT_FORMAT(elf32-i386)
GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a  AS_NEEDED ( /lib/ld-linux.so.2 ) )

or something similar.

Employed Russian