This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problems with shared library using static objects


Jorge Pereira wrote:
> Hello Everyone!
>
> when compile the dynamic project and have duplicate calls for some
> libraries, eg:
>
> gcc -shared -o libfoo.so /path/libhehe.so /path/libhehe.so /path/libhehe.so
>
> This works fine! but when have static files, don't works becouse the
> gcc talks about "redefinitions" of libraries, eg:
>
> gcc -shared -o libfoo.so -Wl,-whole-archive /path/libhehe.a
> /path/libhehe.a /path/libhehe.a
>   
There's a quite good annotation about -whole-archive in the man page of ld:

"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."

After specifying -Wl,-no-whole-archive, I would suppose you'll get some
error messages about multiple definitions, if your libraries contain
overlapping definitions (e.g. of functions). To my opinion, you should
try to avoid multiple definitions of the same symbol, but nevertheless
there's a linker option to allow multiple definitions:

--allow-multiple-definition (-z muldefs)
           Normally when a symbol is defined multiple times, the linker
will report a fatal error. These options allow multiple definitions and
the first definition will be used.

Andi

> My doubt is: exist some way for gcc ignore the multiple references!?
> Thanks!
> --
> Regards,
> +--------------------------------------------+
> Jorge Pereira,
> Blog: http://blog.jorgepereira.com.br/
> +--------------------------------------------+
>
>   


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]