Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Jun 2005 14:52:09 -0600
From:      Tom Schutter <tom.schutter@gmail.com>
To:        freebsd-java@freebsd.org
Subject:   libjava.so RPATH problem
Message-ID:  <af36cf9705063013525ac51f1a@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
I am having problems linking in the Java JVM libraries (libjava.so,
libverify.so, libjvm.so) into my executable.

With these options added to my gcc command:
  -L/usr/local/jdk1.4.2/jre/lib/i386 -ljava -lverify
  -L/usr/local/jdk1.4.2/jre/lib/i386/server -ljvm

It links ok, but when I try to run it I get:
$ ./testme
/libexec/ld-elf.so.1: Shared object "libjava.so" not found, required by
"testme"

At this point ldd tells me:
$ ldd testme
testme:
        libm.so.3 =3D> /lib/libm.so.3 (0x2807c000)
        libjava.so =3D> not found (0x0)
        libverify.so =3D> not found (0x0)
        libjvm.so =3D> not found (0x0)
        libpthread.so.1 =3D> /usr/lib/libpthread.so.1 (0x28097000)
        libc.so.5 =3D> /lib/libc.so.5 (0x280bb000)

Using -Xlinker -rpath -Xlinker PATH_TO_JRE_DIR, I can tell my executable to
look in the JRE dir for libjvm.so.  I have verified that RPATH has been set
in the executable using objdump:
$ objdump -x testme | grep RPATH
  RPATH       /usr/local/jdk1.4.2/jre/lib/i386:/usr/local/jdk1.4.2/jre/lib/=
i386/server

But when I run the executable, it cannot find libjvm.so:
$ ./testme
/libexec/ld-elf.so.1: Shared object "libjvm.so" not found, required by
"libjava.so"

At this point ldd tells me:
$ ldd ./testme
./testme:
        libm.so.3 =3D> /lib/libm.so.3 (0x2807c000)
        libjava.so =3D> /usr/local/jdk1.4.2/jre/lib/i386/libjava.so (0x2809=
7000)
        libverify.so =3D> /usr/local/jdk1.4.2/jre/lib/i386/libverify.so
(0x280b5000)
        libjvm.so =3D> /usr/local/jdk1.4.2/jre/lib/i386/server/libjvm.so
(0x280ca000)
        libpthread.so.1 =3D> /usr/lib/libpthread.so.1 (0x28702000)
        libc.so.5 =3D> /lib/libc.so.5 (0x28726000)
        libjvm.so =3D> not found (0x0)
        libverify.so =3D> not found (0x0)
        libjvm.so =3D> not found (0x0)
        libstdc++.so.4 =3D> /usr/lib/libstdc++.so.4 (0x28800000)

Note that at this point on Linux, testme runs ok.

If I set LD_LIBRARY_PATH, the libraries are found (no output is correct):
$ LD_LIBRARY_PATH=3D/usr/local/jdk1.4.2/jre/lib/i386:/usr/local/jdk1.4.2/jr=
e/lib/i386/server
./testme
$

My questions are:

1) Why is the RPATH in the executable being ignored?

2) When I add the -rpath, I get two copies of a libjvm.so reference in test=
me,
   one that resolves correctly, and one that doesn't.  Why?

3) What is the correct way of linking in libjvm.so?

--=20
Tom Schutter



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?af36cf9705063013525ac51f1a>