Re: is there any way to change the order of name resolution in linking (aside from putting the libraries in the right order?)

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

 



(Jonathan, sorry for sending this twice, but meant to cc group
for reference)

On Sun, Sep 30, 2012 at 3:00 AM, Jonathan Wakely <jwakely.gcc@xxxxxxxxx> wrote:
> On 30 September 2012 02:05, Dan Hitt wrote:
....
>> These are the variations i tried, with the results:
>>     -lX11 (found, but does not resolve symbols)
>
> At the start of the link line there are no symbols to resolve. If
> -lX11 finds both libX11.so and libX11.a then it will prefer the shared
> library, and --whole-archive doesn't affect shared libraries.
>
>>     -lX11a (cannot find)
>
> This looks for a library called libX11a.so or libX11a.a so obviously won't work.
>
>>     -lX11.a (cannot find)
>
> This looks for libX11.a.so or libX11.a.a, so won't work.
>
>>     lX11 (cannot find)
>
> This looks for a file called lX11 in the current dir.
>
>>     libX11 (cannot find)
>>     libX11a (cannot find)
>>     libX11.a (cannot find)
>>     llibX11.a (cannot find)
>
> Similarly, these look for files with that exact name in the current dir.
>
>>     -llibX11.a (cannot find)
>
> This looks for liblibX11.a.so or liblibX11.a.a, so won't work.
>
>> Just for reference, these go in the arguments as
>> -Wl,--whole-archive,<<library goes here>>,--no-whole-archive
>>
>> and so far, the only things that don't bail are -lX11 and
>> /usr/lib/...../libX11.a,
>> and the latter is the only thing that actually resolves any symbols.
>
> You could make the former work (e.g. with --no-as-needed or -static)
> but giving the full path to the static archive works too.

Thanks Jonathan for this analysis.

-static does not work for me (it seems to have global scope, and the linking
fails because ld cannot find something ("-lgcc_s")), but --no-as-needed works
very well.

In fact, with --no-as-needed, the compiled product is only 28K (as opposed to
32K done the right way, and 1.4M done by listing all the needed .a files out
with full paths --- with --no-as-needed only -lX11 is necessary).
(And, "the right way"
means that i did a very poor job of reading the build documentation for
the system i'm using: as it turns out, you certainly can position the libraries,
or, at least position them better than i was; i was using the wrong variables
to get the libraries in.  So if i had read the docs more carefully the
first time i could have
avoided the whole adventure.)

So: thanks for pointing out this very effective, but mysterious
--no-as-needed option.

(Of course, i wonder if my test program were more vigorous if i
wouldn't run into
run-time problems at some point?  But of course that's pure speculation, and i
appreciate your help!!)


dan


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux