Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Having problems with '-rpath' or '-rpath-link' to ocamlopt
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] Having problems with '-rpath' or '-rpath-link' to ocamlopt
From: Narayanan Krishnamurthy <Narayanan.Krishnamurthy@motorola.com>

Hi,

> I have two versions of the PCRE "C" libpcre.so
> libraries. Let us say that the locations
> of the "C" libraries are as follows.
> 
> a) v1.0 : /usr/local/lib/libpcre.so
> b) v2.0 : /mylocal/libpcre.so
> 
> I've built the ocaml pcre package (5.02: pcre.cmxa and pcre.cma) 
> using the "C" v2.0 shared library /mylocal/libpcre.so.
> I have pcre.cmxa in my current working directory.
> 
> With my LD_LIBRARY_PATH set as
> LD_LIBRARY_PATH = /lib:/usr/lib:/usr/local/lib
> I now run
> a) ocamlopt -o myexec pcre.cmxa myexec.o \
>      -cclib -rpath/mylocal -cclib -lpcre
> 
> and find that 'myexec' has the /usr/local/lib/libpcre.so
> as the run-time shared library instead of
> /mylocal/libpcre.so (I use 'ldd' on 'myexec')

People have already answerred about how LD_LIBRARY_PATH overrides
everything else. Here is the relevent section from the ld.so.1 man
page on SunOS 5.8.

     The runtime linker uses a prescribed search path for  locat-
     ing  the  dynamic  dependencies  of  an  object. The default
     search paths are the runpath recorded in  the  object,  fol-
     lowed  by /usr/lib for 32-bit objects or /usr/lib/64 for 64-
     bit objects. This latter component can be modified  using  a
     configuration  file  created  with  crle(1).  The runpath is
     specified when the dynamic object is constructed  using  the
     -R  option to ld(1). LD_LIBRARY_PATH can be used to indicate
     directories to be searched before the default directories.

There are a few workarounds to avoid this kind of problems.
1) give different versions of the same library different file names.
   ELF is intended for that. Most software is installed that way.
   Then you just need a link from libpcre.so to libpcre.so.2, so that
   the library will be found at compile time. At runtime, the system
   will look for libpcre.so.2.
   (Renaming libpcre.so to libpcre.so.2 is not enough, you must write
   the name inside the file with the proper linker option, -h for
   Solaris' ld)
2) As Gerd suggested, if you are root on your machine, rather than
   setting LD_LIBRARY_PATH, you can set the default library path for
   the  machine. The it will only be considered _after_ the runpath.
   On solaris you use crle for that. This is often a good idea anyway
   to add /usr/local/lib to it.

Dynamic linking can be a real pain. Hope this helps.

Jacques Garrigue

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners