LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to know if a symbol refers to a static linked library with "nm" (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-know-if-a-symbol-refers-to-a-static-linked-library-with-nm-875981/)

jose_luis_fdez_diaz 04-19-2011 05:03 PM

How to know if a symbol refers to a static linked library with "nm"
 
Hi,

Given the code below:

<<snip>>

jlfdiaz@narcea:/tmp$ cat foo1.c

int foo1() {}

jlfdiaz@narcea:/tmp$ gcc -c -o foo1.o foo1.c
jlfdiaz@narcea:/tmp$ ar rs libfoo1.a foo1.o
jlfdiaz@narcea:/tmp$ cat kk.c

#include <stdio.h>

int main()
{
foo1();
}

jlfdiaz@narcea:/tmp$ vi kk.c
jlfdiaz@narcea:/tmp$ gcc -I/tmp -L/tmp kk.c -lfoo1

<<snip>>

Is possible to know with "nm", "ldd", "ar" or other unix similar command that executable "a.out" is statically linked with "libfoo1.a".

Thanks in advance,
Jose Luis

neonsignal 04-23-2011 08:42 PM

In general it is not possible, because the process of static linking simply links together the object segments from the various files. It does not matter to the linker (or a debugger) where these segments come from.

You can of course attempt to match up the symbols; in your example where a.out has not been stripped of symbols, nm tells you that that there is a symbol foo1, and you can search all the libraries with nm to find that symbol. But that is clumsy, and if the same symbol is in multiple libraries, you can't tell which one it came from.


All times are GMT -5. The time now is 04:26 PM.