help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Link to static library from DSO without exporting symbols?


From: Boris
Subject: Re: Link to static library from DSO without exporting symbols?
Date: Fri, 29 Sep 2006 11:17:06 +0300

Paul Pluzhnikov wrote:
> "Boris" <boris@gtemail.net> writes:
> [...]
>> Isn't it safe to assume that libfoo probably wants to get
>> linked to some symbols in libbar but does not want to export these
>> symbols?
>
> Not at all. A lot of people build their DSOs like this:
>
> - compile a bunch of sources in multiple directories into src1.a,
> src2.a, etc.
> - link them all into giant DSO like this:
>
>  ld -shared -o giant.so --whole-archive src1.a src2.a
> --no-whole-archive
>
> In this case, the user explicitly wants to have everything in src*.a
> to be included and exported from giant.so

As you must specify --whole-archive in order to include the whole archives 
the default is only to include what is required by any object file. If the 
linker understands that by default he only has to include what is required 
by an object file in my opinion it would make sense to assume that symbols 
from objects in archives need not to be exported. Otherwise the user had 
specified --whole-archive. Then it's pretty clear that symbols should be 
exported as --whole-archive wouldn't make any sense otherwise.

> [...]
> Tough luck. You'll have to explicitly tell the linker what your
> intent is.

Doesn't the existence or non-existence of --whole-archive tell the linker?

> [...]
> bar.o' should do the same. And as I said, from linker perspective
> there
> is not buch difference between 'ld -shared -o foo.so foo.o bar.o' and
> 'ld -shared -o foo.so foo.o bar.a'

I understand that there is not much difference. But there is enough 
difference to make the linker understand that he shouldn't export all 
symbols by default if objects are only linked in because they are used by 
other objects the library is built from? If I know these other objects are 
linked in only because they are required and not because the user insists to 
include the whole archive why should their symbols be exported?

Boris 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]