caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Having problems with '-rpath' or '-rpath-link' to ocamlopt
@ 2003-09-22 17:50 Narayanan Krishnamurthy
  2003-09-22 21:07 ` Olivier Andrieu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Narayanan Krishnamurthy @ 2003-09-22 17:50 UTC (permalink / raw)
  To: caml-list

Hi,

All the following discussions pertain to SunOS 5.8
the gnu linker 'ld 2.9.1', the gcc compiler 'gcc 2.95.2' and
ocaml 3.06.

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')

I tried the following as well and am unable to get
ocamlopt to link in the run-time library /mylocal/libpcre.so.

b) ocamlopt -o myexec pcre.cmxa myexec.o \
     -cclib -R/mylocal -cclib -lpcre
c) ocamlopt -o myexec pcre.cmxa myexec.o \
     -cclib -rpath-link/mylocal -cclib -lpcre

If I unset my LD_LIBRARY_PATH, everything works fine
and the correct library is linked in (I tried
'strings pcre.cmxa' and see the path /mylocal hard-coded
in there).
If I set LD_LIBRARY_PATH as
/lib:/usr/lib:/mylocal:/usr/local/lib
it works fine.

It seems like I am unable to override the LD_LIBRARY_PATH
environment variable using '-rpath' for the linker.
So, what am I doing wrong with the '-rpath' or '-rpath-link'
commands that I'm passing through 'ocamlopt'?
Any information would be greatly appreciated.
Thanks.


Narayanan Krishnamurthy (Nari)

-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Having problems with '-rpath' or '-rpath-link' to ocamlopt
  2003-09-22 17:50 [Caml-list] Having problems with '-rpath' or '-rpath-link' to ocamlopt Narayanan Krishnamurthy
@ 2003-09-22 21:07 ` Olivier Andrieu
  2003-09-22 21:23 ` Gerd Stolpmann
  2003-09-24  2:44 ` Jacques Garrigue
  2 siblings, 0 replies; 4+ messages in thread
From: Olivier Andrieu @ 2003-09-22 21:07 UTC (permalink / raw)
  To: Narayanan Krishnamurthy; +Cc: caml-list

 Narayanan Krishnamurthy [Monday 22 September 2003] :
 > 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')

Sure. LD_LIBRARY_PATH is meant to override the runtime library search
path that is included in the executable (via -rpath or via
LD_RUN_PATH).

 > It seems like I am unable to override the LD_LIBRARY_PATH
 > environment variable using '-rpath' for the linker.

I think you've got it backwards : what you see is LD_LIBRARY_PATH
doing what it is meant to do, that is overriding '-rpath' options.

[I don't know about SunOS actually but that's the behaviour on GNU
systems]. 

-- 
   Olivier

-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Having problems with '-rpath' or '-rpath-link' to ocamlopt
  2003-09-22 17:50 [Caml-list] Having problems with '-rpath' or '-rpath-link' to ocamlopt Narayanan Krishnamurthy
  2003-09-22 21:07 ` Olivier Andrieu
@ 2003-09-22 21:23 ` Gerd Stolpmann
  2003-09-24  2:44 ` Jacques Garrigue
  2 siblings, 0 replies; 4+ messages in thread
From: Gerd Stolpmann @ 2003-09-22 21:23 UTC (permalink / raw)
  To: Narayanan Krishnamurthy; +Cc: caml-list

Am Mon, 2003-09-22 um 19.50 schrieb Narayanan Krishnamurthy:
> Hi,
> 
> All the following discussions pertain to SunOS 5.8
> the gnu linker 'ld 2.9.1', the gcc compiler 'gcc 2.95.2' and
> ocaml 3.06.
> 
> 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

No chance. LD_LIBRARY_PATH is searched before any RPATH that is recorded
in the .so file.

> 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')
> 
> I tried the following as well and am unable to get
> ocamlopt to link in the run-time library /mylocal/libpcre.so.
> 
> b) ocamlopt -o myexec pcre.cmxa myexec.o \
>      -cclib -R/mylocal -cclib -lpcre
> c) ocamlopt -o myexec pcre.cmxa myexec.o \
>      -cclib -rpath-link/mylocal -cclib -lpcre

If you do "dump -Lv myexec" you will see that the effect is the same:
The RPATH section of the file is set to /mylocal.

> If I unset my LD_LIBRARY_PATH, everything works fine
> and the correct library is linked in (I tried
> 'strings pcre.cmxa' and see the path /mylocal hard-coded
> in there).
> If I set LD_LIBRARY_PATH as
> /lib:/usr/lib:/mylocal:/usr/local/lib
> it works fine.
> 
> It seems like I am unable to override the LD_LIBRARY_PATH
> environment variable using '-rpath' for the linker.
> So, what am I doing wrong with the '-rpath' or '-rpath-link'
> commands that I'm passing through 'ocamlopt'?
> Any information would be greatly appreciated.
> Thanks.

Because of the phenomenons you have found it is a very bad idea to set
LD_LIBRARY_PATH. This variable is a debugging aid, and no substitute for
a proper system setup.

Fortunately you run Solaris 8. For previous versions, the only way out
is to drop the idea of extending the system search path for libraries,
and to use RPATH all the time. For Solaris 8, you can modify the system
search path with the crle utility:

crle -l /usr/lib -l /usr/local/lib

Note that using crle is dangerous, and wrong usage may corrupt your
system (you can end up that you cannot start any program), so read the
man page.

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
------------------------------------------------------------

-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Having problems with '-rpath' or '-rpath-link' to ocamlopt
  2003-09-22 17:50 [Caml-list] Having problems with '-rpath' or '-rpath-link' to ocamlopt Narayanan Krishnamurthy
  2003-09-22 21:07 ` Olivier Andrieu
  2003-09-22 21:23 ` Gerd Stolpmann
@ 2003-09-24  2:44 ` Jacques Garrigue
  2 siblings, 0 replies; 4+ messages in thread
From: Jacques Garrigue @ 2003-09-24  2:44 UTC (permalink / raw)
  To: Narayanan.Krishnamurthy; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-09-24  2:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-22 17:50 [Caml-list] Having problems with '-rpath' or '-rpath-link' to ocamlopt Narayanan Krishnamurthy
2003-09-22 21:07 ` Olivier Andrieu
2003-09-22 21:23 ` Gerd Stolpmann
2003-09-24  2:44 ` Jacques Garrigue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).