Programming This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
04-05-2010, 07:08 AM
|
#1
|
|
LQ Newbie
Registered: Apr 2010
Posts: 2
Rep:
|
'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();
}
Makefile:
all:
gcc -c -fPIC statLib.c
ar clq libStat.a statLib.o
gcc -c -fPIC sharedLib.c
gcc -shared -o libShared.so sharedLib.o /path/to/static/lib/libStat.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
$
Any help will be highly appreciated.
|
|
|
|
04-05-2010, 07:55 AM
|
#2
|
|
Senior Member
Registered: May 2005
Posts: 4,420
|
By
Code:
gcc -shared -o libShared.so sharedLib.o /path/to/static/lib/libStat.a
you are telling the linker to link everything together, don't you ?
|
|
|
|
04-05-2010, 11:12 AM
|
#3
|
|
Senior Member
Registered: May 2005
Posts: 4,420
|
|
|
|
|
04-06-2010, 03:46 AM
|
#4
|
|
LQ Newbie
Registered: Apr 2010
Posts: 2
Original Poster
Rep:
|
Hi Sergei,
Thanks for your response.
>>> 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!
|
|
|
|
04-06-2010, 04:04 AM
|
#5
|
|
Senior Member
Registered: May 2005
Posts: 4,420
|
Quote:
Originally Posted by painulyarun
Hi Sergei,
Thanks for your response.
>>> 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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:38 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|