Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 03-02-2006, 08:41 PM   #1
Registered: Aug 2005
Location: Pittsburgh, PA, USA
Distribution: Redhat 9, OS X 10.4.x, Win2K
Posts: 85

Rep: Reputation: 15
Hiding Symbols in Static Libraries


When I am writing static libraries, I try to minimize namespace pollution as much as possible by taking care not to export all sorts of silly little global symbols all over the place. But in some situations, there is no way to avoid having a symbol exported from a library, even though the symbols don't actually need to be used outside of the library (e.g. source code generated by other programs that I don't have much control over, or pre-compiled third-party libs).

Is there any way to have ar/ranlib -not- place certain symbols in the table of contents when I build the library? I have tried using objcopy to "filter" symbols out of the library but I could not get it to work like I wanted, the symbols still were being exported, according to nm.

If hiding the symbols completely is not an option, is there some way to alias the symbols to different names in the archive?


Last edited by JCipriani; 03-02-2006 at 08:42 PM.
Old 03-03-2006, 01:08 PM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

As you already know, Windows .dll's and AIX shared libraries let you explicitly control which symbols are and are not publicly exported when you create a shared library. Linux, as far as I know, doesn't. So (again, AFAIK) you're pretty much stuck with using "static":

'Hope that helps .. PSM
Old 03-03-2006, 05:15 PM   #3
Registered: Aug 2005
Location: Pittsburgh, PA, USA
Distribution: Redhat 9, OS X 10.4.x, Win2K
Posts: 85

Original Poster
Rep: Reputation: 15
Thanks for the links! The first one had the information I was looking for. I'll test it out more thoroughly later but "objcopy -L symbol_name" seems to do the trick (I had originally been playing with the "-N" option, not "-L").

Thanks again,


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
Undefined references with static libraries Nightfox Programming 2 10-28-2005 06:43 PM
Making static symbols private/local in shared libraries skoona Programming 1 02-18-2005 03:14 PM
compiling with shared and static libraries jinksys Programming 1 11-22-2003 04:54 AM
gaim trying to link static and shared libraries rose_bud4201 Linux - Software 0 09-28-2003 12:27 AM
Finding and Linking Static Libraries with gcc neorich Programming 15 08-10-2003 04:03 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:23 AM.

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
Open Source Consulting | Domain Registration