[svlug] modify default directory search order for GCC

Roland Krause rokrau at yahoo.com
Tue Aug 8 14:27:51 PDT 2006


In case you really need a specific version of libz for your
application, you can always link statically. This has some advantages
and some obvious disadvantages but it gets rid of your problem.

Another option is to specify -rpath when linking. This adds a directory
to the runtime library search path. Refer to the manpage for details
but for quick reference I included the following excerpt: 

Begin of man:ld excerpt.

The linker uses the following search paths to locate required shared
libraries. 
1.
 Any directories specified by -rpath-link options. 
2.
 Any directories specified by -rpath options. The difference between
-rpath and -rpath-link is that directories specified by -rpath options
are included in the executable and used at runtime, whereas the
-rpath-link option is only effective at link time. It is for the native
linker only. 

End of man:ld excerpt.

Additionally you can specify LD_PRELOAD and explicitly load the shared
library. Example

LD_PRELOAD=/home/you/libz.so myprogram.exe

Further, LD_LIBRARY_PATH has become problematic in recent distributions
(e.g. FC5), if specified in /etc/profile.d scripts it is overwritten
somewhere during the startup sequence.

Finally - "Hi Ken, long time no hear :-)"
Roland


--- Fabrizio Bertocci <fabriziobertocci at gmail.com> wrote:

> > i read man ld before, and it does say that LD_LIBRARY_PATH is
> before /lib
> > and /usr/lib, however,
> > if it already has /usr/lib/libz.so from ldd output, it should pick
> up that
> > first, am i right?
> >
> 
> 
> I think I got the problem: ldd is not just looking at libz.so, but is
> looking also at a particular library version.
> So, for the example you sent, at first I only copied libz.so (cp
> /usr/lib/libz.so .) in my local directory, and after setting
> LD_LIBRARY_PATH
> to my local dir, ldd still reported libz from /usr/lib.
> Then I copied ALL the files (cp -a /usr/lib/libz.so.* .), including
> the
> symlinks. After this ldd correctly reported libz from my local dir.
> 
> Fabrizio
> > _______________________________________________
> svlug mailing list
> svlug at lists.svlug.org
> http://lists.svlug.org/lists/listinfo/svlug
> 





More information about the Svlug mailing list