LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: 0
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
 
Old 04-23-2011, 08:42 PM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
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.
  


Reply



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 08:40 PM
Can someone give me the definition of "Kernel Symbol" and "EXPORT_SYMBOL" ?? Raynus Programming 2 08-30-2008 07:19 PM
avgscan "relocation error" "undefined symbol: __dynamic_cast_2" Monster_user Linux - Software 0 02-22-2006 11:57 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 04:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:11 AM.

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