OT: Linux shared lib question

e-t172 e-t172 at akegroup.org
Tue May 13 03:50:59 PDT 2008


Bill Baxter a écrit :
> So I figured if it can do that then surely this would work:
> 
>   gcc -shared -Wl,-soname,lib${name}.so.1 -o lib${name}.so.1.1 \
>       libmylibrary.a
> 
> where libmylibrary.a is a lib containing a.o, b.o, and c.o.  After all a 
> .a archive is basically just a concatenation of .o files in a convenient 
> package.
> 
> However, though the command runs without reporting an error, the 
> resulting .so does not contain the contents of libmylibrary.a.

man ld:

"--whole-archive
For each archive mentioned on the command line after the --whole-archive 
option, include every object file  in  the  archive  in the link, rather 
than searching the archive for the required object files. This is 
normally used to turn an archive file into a shared  library,  forcing 
every  object  to  be included in the resulting shared library.  This 
option may be used more than once.

Two  notes when using this option from gcc: First, gcc doesn’t know 
about this option, so you have to use -Wl,-whole-archive.  Second, don’t 
  forget  to  use  -Wl,-no-whole-archive  after  your  list  of 
archives,  because  gcc will add its own list of archives to your link 
and you may not want this flag to affect those as well."


More information about the Digitalmars-d-learn mailing list