'nm' lists all symbols - including static library symbols
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
'nm' lists all symbols - including static library symbols
Hi All,
By issuing the 'nm' command on shared library (internally using one static library), the functions exposed by static library is also being listed, Which allows to use internal functions which is of course not intended.
I have one static library having A(), B() and C() functions. Creating one shared library which has function XYS() that is using A() and B() functions from Static library. While doing 'nm' on shared library, alll the static library function are being listed.
Static Lib:
#include<stdio.h>
void A(char *msg)
{
printf("\nMessage: %s\n", msg);
}
int B(int a,int b)
{
return (a+b);
}
void C()
{
}
Shared Lib:
#include<stdio.h>
extern int sumNos(int,int);
int XYZ(void)
{
printf("\nSharedLibFun\n"); A();
}
Output geneerated after building shared object "libShared.so"
$ nm libShared.so
0000000000000798 T A
00000000000007bb T B
0000000000100b18 A __bss_start
00000000000007cd T C
00000000000006d0 t call_gmon_start
0000000000100b18 b completed.1
0000000000100918 d __CTOR_END__
0000000000100910 d __CTOR_LIST__
w __cxa_finalize@@GLIBC_2.2.5
00000000000007e0 t __do_global_ctors_aux
00000000000006f0 t __do_global_dtors_aux
0000000000100b08 d __dso_handle
0000000000100928 d __DTOR_END__
0000000000100920 d __DTOR_LIST__
0000000000100938 A _DYNAMIC
0000000000100b18 A _edata
0000000000100b20 A _end
0000000000000818 T _fini
0000000000000740 t frame_dummy
0000000000000908 r __FRAME_END__
0000000000100ad0 A _GLOBAL_OFFSET_TABLE_
w __gmon_start__
0000000000000668 T _init
0000000000100930 d __JCR_END__
0000000000100930 d __JCR_LIST__
w _Jv_RegisterClasses
0000000000100b10 d p.0
U printf@@GLIBC_2.2.5
000000000000076c T XYZ
$
>>> you are telling the linker to link everything together, don't you ?
Yes, i think we need to provide the static library while creating shared object here. Please let me know your suggestions.
I went throgh the link you provided, tried with "-Wl,-export-dynamic" options but that didn't help
>>> you are telling the linker to link everything together, don't you ?
Yes, i think we need to provide the static library while creating shared object here. Please let me know your suggestions.
I went throgh the link you provided, tried with "-Wl,-export-dynamic" options but that didn't help
Thanks!
You have to understand how/when libraries are used. If you want only certain symbols to be taken from something, that something needs to be specified to linker as a library, not just as an item on command line.
The URL I gave you contains examples in which some items are specified as a library.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.