Linking against shared objects that reside at different paths on link-time versus runtime?

Dun Peal dunpealer@gmail.com
Mon Jun 27 22:07:00 GMT 2011


On Tue, Jun 21, 2011 at 12:06 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> -lbar tells the linker to look for
> libbar.so, and if it finds libbar.so with a soname it creates a
> dependency on the soname, if it finds libbar.so without a soname it
> creates a dependency on the file's name, including the full path when
> you link to /foo/bar.so.  So -lxxx can only match a file called
> libxxx.so (or libxxx.a), to do what you suggest it would have to open
> every single file and check if it has the requested soname, that won't
> work.

Just to make sure I understand: you are saying that with `-L/foo
-lbar`, ld is going to look for `libbar.so` inside `/foo`, check if it
has an soname, and if it does: link to it.

But how is it going to find the library with the same soname at
runtime?  Will it have to open every `lib*` file in the load path
(i.e. the system default + LD_LIBRARY_PATH) and look at its soname?

Also, if `libbar.so` doesn't have an soname, what exactly did you mean
when you wrote that the binary product will include the "full path"?

Thanks, D.



More information about the Gcc-help mailing list