Option -static

Mike Frysinger vapier@gentoo.org
Fri Jan 8 03:12:00 GMT 2010


On Thursday 07 January 2010 15:31:12 Takis Psarogiannakopoulos wrote:
> On Thu, 7 Jan 2010, H.J. Lu wrote:
> > On Thu, Jan 7, 2010 at 10:02 AM, Ian Lance Taylor <iant@google.com> wrote:
> > > If anybody actually implements this, I think better would be something
> > > like -Bprefer-static and -Bprefer-dynamic, and make them position
> > > dependent like -Bstatic and -Bdynamic.
> >
> > Sounds good to me.
> 
> I would implement that option if nobody else does/has already . I needed
> in any case for the OS I am running.  -Bprefer-static  sounds good,
> I am not sure about the position dependent part, as -Bstatic and -Bdynamic
> already do exactly that.
> -Bprefer-dymamic is in any case the default behavior of gold/gnu ld
> right? Nothing to implement really.

if you do attempt this, make sure you account for edge cases like 
shared/static libs being in different dirs and encountering them in different 
orders.  atm, the default gnu ld will pick the first library it finds whether 
it's static or dynamic.  i'd expect a "prefer" option to search all paths for 
the preferred type and if that fails, fall back to the default behavior (any 
valid type).  perhaps you'll need a third option of "-Bprefer-default" so that 
the default behavior can be restored to the implicit link options ...

examples would be:
$ tree
./main.c
./shared/libfoo.so
./static/libfoo.a
$ gcc main.c -Lshared -Lstatic -Wl,-Bprefer-static -lfoo -Wl,-Bprefer-default
$ gcc main.c -Lstatic -Lshared -Wl,-Bprefer-static -lfoo -Wl,-Bprefer-default
	... static/libfoo.a is used ...
$ gcc main.c -Lshared -Lstatic -Wl,-Bprefer-dynamic -lfoo -Wl,-Bprefer-default
$ gcc main.c -Lstatic -Lshared -Wl,-Bprefer-dynamic -lfoo -Wl,-Bprefer-default
	... static/libfoo.so is used ...
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <https://sourceware.org/pipermail/binutils/attachments/20100108/87eceb65/attachment.sig>


More information about the Binutils mailing list