Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2003-09-24 (02:46)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] Having problems with '-rpath' or '-rpath-link' to ocamlopt
From: Narayanan Krishnamurthy <>


> I have two versions of the PCRE "C"
> libraries. Let us say that the locations
> of the "C" libraries are as follows.
> a) v1.0 : /usr/local/lib/
> b) v2.0 : /mylocal/
> I've built the ocaml pcre package (5.02: pcre.cmxa and pcre.cma) 
> using the "C" v2.0 shared library /mylocal/
> 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/
> as the run-time shared library instead of
> /mylocal/ (I use 'ldd' on 'myexec')

People have already answerred about how LD_LIBRARY_PATH overrides
everything else. Here is the relevent section from the 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 to, so that
   the library will be found at compile time. At runtime, the system
   will look for
   (Renaming to 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 Archives:
Bug reports: FAQ:
Beginner's list: