LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Hiding Symbols in Static Libraries (https://www.linuxquestions.org/questions/programming-9/hiding-symbols-in-static-libraries-421111/)

JCipriani 03-02-2006 08:41 PM

Hiding Symbols in Static Libraries
 
Hi,

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?

Thanks!
JC

paulsm4 03-03-2006 01:08 PM

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":

http://linuxgazette.net/issue55/tag/5.html
http://www.linux.com/howtos/Program-...ibraries.shtml

'Hope that helps .. PSM

JCipriani 03-03-2006 05:15 PM

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,
Jason


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