Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 348
Crazy Chenz Avatar asked Oct 23 '09 17:10

Crazy Chenz


2 Answers

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.

like image 113
Employed Russian Avatar answered Jan 27 '23 18:01

Employed Russian


gcc -Wl,--trace file.c

will print list of input files for ld

like image 45
Oleksandr Tymoshenko Avatar answered Jan 27 '23 18:01

Oleksandr Tymoshenko