Hiding names in static libraries

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2006
Posts: 7
Reputation: lastcraft is an unknown quantity at this point 
Solved Threads: 0
lastcraft lastcraft is offline Offline
Newbie Poster

Hiding names in static libraries

 
0
  #1
Jan 13th, 2008
Hi.

I've written a small static (Unix .a) library, as usual made from a bunch of .c and .h files. A lot of the functions in the .h files are internal to the final library. Only a few of the .h files containing the public interface.

How can I hide the internal names from people who will be using the library? I'd rather avoid giving silly prefixes to the internal stuff.

yours, Marcus
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Hiding names in static libraries

 
0
  #2
Jan 13th, 2008
Supply a different .h file to people using the library than the one used to compile it.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 7
Reputation: lastcraft is an unknown quantity at this point 
Solved Threads: 0
lastcraft lastcraft is offline Offline
Newbie Poster

Re: Hiding names in static libraries

 
0
  #3
Jan 13th, 2008
Hi...

Originally Posted by Duoas View Post
Supply a different .h file to people using the library than the one used to compile it.
Well, I'm pretty sure that is what I've done. The top level .h does not include the internal .h files (although the .c files the .o files were created from obviously do).

The problem is the the .a archive exports a load of symbols that can clash with user types/functions even though they are not in the header (unless I'm doing something really dumb, which I suspect I am). Using the strip utility to remove these stops the .a archive linking internally when it's compiled in to other projects.

The .a archive contains 4 .o files. Is there a way I can compile these into a single.o or .a file with just the symbols in the .h file shipped with it?

I'm currently poking around in the autoconf toolset to see how that does it, but that could take me days to figure out. I also want to avoid autoconf dependencies if I can.

Any ideas?

yours, Marcus
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Hiding names in static libraries

 
0
  #4
Jan 13th, 2008
If the 4 .o files are inter-dependent (that is, you either have all of them or none of them), then you can use 'ld' to produce an incremental link of the 4 .o files to produce a single .o file (which you can then put in a library if you want).

ld also has many options for manipulating the symbol table, so you should be able to emit only the public API when you're done.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,485
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Hiding names in static libraries

 
0
  #5
Jan 13th, 2008
If all the functions are in one *.c file then you can declare all the internal functions with the static keyword and the symbols will not appear in the libraries or be accessable outside the *.c file.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 7
Reputation: lastcraft is an unknown quantity at this point 
Solved Threads: 0
lastcraft lastcraft is offline Offline
Newbie Poster

Re: Hiding names in static libraries

 
0
  #6
Jan 13th, 2008
Hi...

Originally Posted by Salem View Post
If the 4 .o files are inter-dependent (that is, you either have all of them or none of them), then you can use 'ld' to produce an incremental link of the 4 .o files to produce a single .o file (which you can then put in a library if you want).

ld also has many options for manipulating the symbol table, so you should be able to emit only the public API when you're done.
Excellent. I'll read the docs on ld. I thought there had to be something like this.

Cheers.

yours, Marcus
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 7
Reputation: lastcraft is an unknown quantity at this point 
Solved Threads: 0
lastcraft lastcraft is offline Offline
Newbie Poster

Re: Hiding names in static libraries

 
0
  #7
Jan 13th, 2008
Hi...

Originally Posted by Ancient Dragon View Post
If all the functions are in one *.c file then you can declare all the internal functions with the static keyword and the symbols will not appear in the libraries or be accessable outside the *.c file.
I'm afraid they are not. It's a good few hundred lines of code (there are actually already internal statics as well), so I'd like to keep them separate.

yours, Marcus
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC