Article View: comp.unix.programmer
Article #3516GCC: How to limit what symbols are exposed/exported ?
From: Musa Kenema
Date: Wed, 23 Apr 2003 16:12
Date: Wed, 23 Apr 2003 16:12
89 lines
5226 bytes
5226 bytes
Hi,
I am new to UNIX (and C programming for that matter) and am having some
trouble creating Libraries - Shared (.so) and static (.a) - so please
bear with me.
When I try to link my test program to my library "libUtils.a", I keep
getting error warnings that there are duplicate definitions of some of
my variables and functions. This happens because within the different
object files that I put together to create my "libUtils.a" library, I
have some similar named variables and functions - but none of these are
being exposed through my header files, but it appears that gcc is
exposing everything in the files.
My question is, when using gcc under Linux or Solaris, is there a way to
select what items/symbols are exposed (similar to a .DEF file under
windows maybe) ?
For your information, this is how I build me library:
+-------------------------------------------------------+
| File : Utils_Fn_A.c |
+-------------------------------------------------------+
| |
|int m_Flag1 = 0; |
| |
|long M_Utils_Fn_A1( long Parameter ) { |
| do something |
|} |
| |
|long M_Utils_Fn_internal( double Parameter ) { |
| do something else |
|} |
| |
+-------------------------------------------------------+
+-------------------------------------------------------+
| File : Utils_Fn_A.h |
+-------------------------------------------------------+
| |
|long M_Utils_Fn_A1( long Parameter ) |
| |
+-------------------------------------------------------+
+-------------------------------------------------------+
| File : Utils_Fn_B.c |
+-------------------------------------------------------+
| |
|int m_Flag1 = 0; |
|int m_Flag2 = 1; |
| |
|long M_Utils_Fn_B1( long Parameter ) { |
| do something |
|} |
| |
|long M_Utils_Fn_internal( double Parameter ) { |
| do something else |
|} |
| |
+-------------------------------------------------------+
+-------------------------------------------------------+
| File : Utils_Fn_B.h |
+-------------------------------------------------------+
| |
|long M_Utils_Fn_B1( long Parameter ) |
| |
+-------------------------------------------------------+
+--------------------------------------------+
|gcc -c Utils_Fn_A.c |
|gcc -c Utils_Fn_B.c |
| |
|ar rc libUtils.a Utils_Fn_A.o Utils_Fn_B.o |
|ranlib libUtils.a |
| |
+--------------------------------------------+
When I try to link my test program with :
gcc test.c -lm -L. libUtils.a
I get errors like :
ld: fatal: symbol `M_Utils_Fn_internal' is multiply defined:
(file libUtils.a(Utils_Fn_A.o) and file libUtils.a(Utils_Fn_B.o));
Thanks,
M.
Technical Details
Message-ID:
<b86e1a$o1h$1$830fa17d@news.demon.co.uk>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,cd0a48876d200a5b,start X-Google-Attributes: gid11318c,public X-Google-Thread: fc89c,cd0a48876d200a5b,start X-Google-Attributes: gidfc89c,public X-Google-ArrivalTime: 2003-04-23 09:12:27 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: "Musa Kenema" <musakeneSNIPSNIPma@hotmail.com> Newsgroups: comp.unix.programmer,gnu.gcc.help Subject: GCC: How to limit what symbols are exposed/exported ? Date: Wed, 23 Apr 2003 17:12:27 +0100 Lines: 91 Message-ID: <b86e1a$o1h$1$830fa17d@news.demon.co.uk> NNTP-Posting-Host: barakat.demon.co.uk X-Trace: news.demon.co.uk 1051114346 24625 80.177.21.111 (23 Apr 2003 16:12:26 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Wed, 23 Apr 2003 16:12:26 +0000 (UTC) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Priority: 3 X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MSMail-Priority: Normal