This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: ar: POSIX way of creating static library containing similarly named objects
- From: Miguel Guedes <miguel dot a dot guedes at gmail dot com>
- To: binutils at sourceware dot org
- Date: Tue, 23 Apr 2013 10:46:14 +0000 (UTC)
- Subject: Re: ar: POSIX way of creating static library containing similarly named objects
- References: <kkoj1h$1bi$1 at ger dot gmane dot org> <5170F933 dot 20506 at redhat dot com>
Hi Nick,
On Fri, 19 Apr 2013 08:58:43 +0100, nick clifton wrote:
> 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:
>
> % ar cr libstate.a src/namespace_foo/state.o % ar q libstate.a
> src/namespace_bar/state.o % ar s libstate.a % readelf -c libstate.a
> Index of archive libstate.a: (2 entries, 0x8 bytes in the symbol
> table)
> Binary libstate.a(state.o) contains:
> foo
> Binary libstate.a(state.o) contains:
> foo
This technique worked really well until I noticed strange behaviour when
running programs generated from partial builds where symbols were getting
duplicated in the library and not replaced as they should.
Only solution to this (that I can see) would be to rebuild the library
each time a partial build is initiated and add every single object using
the `q' option, but in large projects this isn't really viable.
Another possible solution is to drop my pedantic hat and just go with
Cary's suggestion of using a thin archive instead.
Nick and Cary, thanks for the input.