ar: POSIX way of creating static library containing similarly named objects

Cary Coutant ccoutant@google.com
Fri Apr 19 21:20:00 GMT 2013
>> Can `ar' be used to create a static library comprised of the objects
>> above without either of which replacing any symbols? In other words, both
>> namespace_foo/state.o and namespace_bar/state.o are put into the same
>> library but no symbols are replaced.
>
> Use the 'q' option rather than the 'r' option when adding the object files
> to the library - and create the symbol index after adding the objects,
> rather than at the same time.  Ie:

If you don't need the archive to be self-contained, you can also use a
thin archive:

$ ar crT libstate.a src/namespace*/state.o
$ ar t libstate.a
src/namespace_bar/state.o
src/namespace_foo/state.o

Here, libstate.a contains just the symbol table, with references to
the object files in their separate directories.

-cary



More information about the Binutils mailing list