Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-19-2011, 06:03 PM   #1
LQ Newbie
Registered: Apr 2011
Posts: 1

Rep: Reputation: 0
How to know if a symbol refers to a static linked library with "nm"


Given the code below:


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()

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


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
Old 04-23-2011, 09:42 PM   #2
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Buster (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 359Reputation: 359Reputation: 359Reputation: 359
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.
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
What's the difference between static and dynamically linked library... trist007 Linux - Newbie 5 09-19-2010 09:40 PM
Can someone give me the definition of "Kernel Symbol" and "EXPORT_SYMBOL" ?? Raynus Programming 2 08-30-2008 08:19 PM
avgscan "relocation error" "undefined symbol: __dynamic_cast_2" Monster_user Linux - Software 0 02-22-2006 12:57 PM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 03:32 PM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 05:20 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:03 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration