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

╄→尐↘猪︶ㄣ 提交于 2020-01-31 04:44:04

问题


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:


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.




回答2:


gcc -Wl,--trace file.c

will print list of input files for ld



来源:https://stackoverflow.com/questions/1614769/how-to-i-find-the-filename-of-a-library-via-the-library-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!