Skip to content

LD_LIBRARY_PATH is harmfull

4 messages · Brian Ripley, Alexander Klimov

#
Please use R-devel for comments about R development (moved there).
On Mon, 21 Feb 2005, Alexander Klimov wrote:

            
I don't believe that happens unless `home/lib' is not in the library paths 
at all.  I've checked man ld and man ld.so.1 on Solaris 8, and neither 
appear to mention that -R is ignored if LD_LIBRARY_PATH is set.  I think 
that is a (well-buried) Solaris-specific gotcha.
Please take a look at e.g. config.site, which explains this under LDFLAGS, 
(as does the R-admin manual which INSTALL asks you to read).
[Which is Solaris specific, despite the site name.]

Unfortunately, the alternatives lead to even more problems, and this is 
the first report we have had for years of a problem (which can be solved 
on reading the documentation).  As the R-admin manual points out, we 
regularly test on Solaris 8 and give an example there of setting LDFLAGS 
under the Solaris section.

Use of -R is harmful for sure!  It stops R being relocatable (so it either 
could not be tested before being installed or it would not run after 
installation), and it is not at all portable.

Maybe one day when we have libtool tamed we will be able to use the
multiple equivalents of -R or LD_RUN_PATH in a portable-enough way.
#
Hi.
On Mon, 21 Feb 2005, Prof Brian Ripley wrote:
Notice that I do have libgcc_s in /usr/local/lib, but it is for
gcc2.95, so ldd said `(version not found)' because there is a library
but with wrong version -- I guess other libraries simply are not
considered at all.
The standard meaning of LD_LIBRARY_PATH is to be considered *before*
any other path.
Note that I do not need any *additional* flags because
-L<home>/lib and -R<home>/lib are already in my specs file.
AFAIK LD_LIBRARY_PATH has the same semantic on Linux and every other
recent *nix: it overrides system-wide defaults (e.g., crle on solaris
and ldconfig on linux) as well as embeded paths; -R or -rpath are also
common among *nixes.
Note that I do not have a problem with R installation, but I was
troubled to load an extension (gmp in my case).
Could you, please, enlight me what page of R-admin.pdf I missed?
B.7.3 (p.22) says nothing about my case (32-bit solaris and gcc >3.3)
Testing before installtion is exactly the purpose of LD_LIBRARY_PATH:
you compile with -R for final installation and use
LD_LIBRARY_PATH=<build-dir>/lib during testing. Alternatively you can
use $ORIGIN so that libraries are searched in the places relative to
executable itself.
And could you name at least a single modern platform which supports
shared libraries and does not support an equivalent of -R for linking?

BTW, LD_LIBRARY_PATH also has different names on different *nix
(e.g., SHLIB_PATH on HP-UX, although AFAIK HP-UX also supports
LD_LIBRARY_PATH)
Nice to know that such plans exist :-)
#
On Mon, 21 Feb 2005, Alexander Klimov wrote:

            
Something is very strange: notice you say you have 3.4.3 and it is looking 
for GCC_3.3!  I get

         libgcc_s.so.1 =>         /usr/local/lib/libgcc_s.so.1

and no version number.
Yes.  That is not what you say happens for you, though, rather you are 
sayin *instead of*.
You need something to find R's shared libraries, e.g. libRlapack.
The issue is if they are ignored, not if they are overridden.
No, as I don't have your layout.  But it _is_ there:

If you have libraries and header files, e.g., for @acronym{GNU}
readline, in non-system directories, use the variables @code{LDFLAGS}
(for libraries, using @samp{-L} flags to be passed to the linker) and
@code{CPPFLAGS} (for header files, using @samp{-I} flags to be passed to
the C/C++ preprocessors), respectively, to specify these locations.
These default to @file{/usr/local/lib} and @file{/usr/local/include} to
catch the most common cases.

[You clearly do so have.]

...

Library paths specified as @option{-L/lib/path} in @code{LDFLAGS} are
collected together and prepended to @env{LD_LIBRARY_PATH} (or your
system's equivalent), so there should be no need for @option{-R} or
@option{-rpath} flags.

and in config.site.
It gives an example of setting LDFLAGS: you cannot expect every user's 
setup to be mentioned.
Windows (probably the most-used platform for R).

I actually said -R is not portable, and many platforms do not have that.

  
    
#
On Mon, 21 Feb 2005, Prof Brian Ripley wrote:
This is as it is supposed to be. Try to
$ objdump -p file | grep GCC_
where file is either executable or library, e.g.,
objdump -p ~/soft/lib/libgcc_s.so | grep GCC_

In order to get better understanding of DSO consider reading
http://people.redhat.com/drepper/dsohowto.pdf
It is because in your case .so has correct version
Let's try again: my problem is not that I do not have libgcc_s in the
search path, but that due to R's LD_LIBRARY_PATH the first libgcc_s in
the path has incorrect version.
This could be easily done with -R, and due to $ORIGIN this could be
simpler than with LD_LIBRARY_PATH
Who said that they are *always* ignored? They definitely ignored if
due to LD_LIBRARY_PATH some incorrect library was found before.
But, as I already said this is not applicable to me since I do not
need any additional flags!
And since I have not specified anything for -L nothing should be added
to LD_LIBRARY_PATH. But I guess I should understand this as the
default /usr/local/lib will be added which I don't think a good idea:
if everything works for a user with his LD_LIBRARY_PATH, why add
something which is not under R_HOME.
Let's try again: I do not need any -L flags.
Yes, you are right, OTOH dll support on windows is very different
anyway.