| | |
Hiding names in static libraries
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2006
Posts: 7
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Dec 2006
Posts: 7
Reputation:
Solved Threads: 0
Hi...
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
•
•
•
•
Supply a different .h file to people using the library than the one used to compile it.
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
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.
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.
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.
•
•
Join Date: Dec 2006
Posts: 7
Reputation:
Solved Threads: 0
Hi...
Excellent. I'll read the docs on ld. I thought there had to be something like this.
Cheers.
yours, Marcus
•
•
•
•
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.
Cheers.
yours, Marcus
•
•
Join Date: Dec 2006
Posts: 7
Reputation:
Solved Threads: 0
Hi...
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
•
•
•
•
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.
yours, Marcus
![]() |
Other Threads in the C Forum
- Previous Thread: Incompatible pointer type problem
- Next Thread: undefined reference to....
| Thread Tools | Search this Thread |
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide inches infiniteloop initialization interest kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer pointers posix power probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string strings structures suggestions systemcall test testautomation unix urboc user voidmain() wab win32api windows.h






