Do you know how to create a library file?

Rupert Wood me@rupey.net
Tue Feb 5 03:37:00 GMT 2002


CC111310 wrote:

> I'm hoping that somebody out there knows how to create a lib (i.e.
> .a file).

Use 'ar' - look at its info page or man page for help. If you don't have
ar installed, you can get it from the GNU binutils package.
Traditionally, newly generated archives are also passed through ranlib -
but I think ranlib is a no-op on most modern unix-likes.

(One exception that I know of is generating an archive of C++ files as
compiled by Sun's own C++ compiler; in this instance, you'd want to use
'CC -xar'. It sounds like you're using GNU tools, though.)

If you have any complex lib requirements, e.g. shared libraries for
multiple platforms, you may want to look at the GNU libtool package.

> I think I need to create a new lib file that has the necessary
> functions that i need (and remove the functions that i don't use).

This probably isn't necessary. Assuming each function is defined in a
separate object file within the library (as is usual) then the linker
will already only import the functions that it needs.

Good luck,
Rup.



More information about the Gcc-help mailing list