LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Trouble Invoking JVM From C: Cannot Find libjava.so. (https://www.linuxquestions.org/questions/programming-9/trouble-invoking-jvm-from-c-cannot-find-libjava-so-106550/)

eric.r.turner 10-20-2003 10:36 PM

Trouble Invoking JVM From C: Cannot Find libjava.so.
 
I'm trying to compile and run the code from the tutorial at
http://java.sun.com/docs/books/tutor...king/invo.html
(invoking the Java Virtual Machine from C), and am running into problems.
My setup is:
  • Slackware Linux 9.0 with kernel 2.4.20
  • gcc 3.2.2
  • J2SE 1.4.2_01

The tutorial says to compile (on Solaris) using:

Code:

cc -I<where jni.h is> -L<where libjava.so is> -ljava invoke.c
so I try using:
Code:

    gcc -o invoke \
    -I/usr/local/j2sdk1.4.2_01/include \
    -L/usr/local/j2sdk1.4.2_01/jre/lib/i386 \
    -ljava \
    invoke.c

The first error from that attempt is "In file included from
invoke.c:1: /usr/local/j2sdk1.4.2_01/include/jni.h:27:20:
jni_md.h: No such file or directory"

So I find the directory that jni_md.h is in and add that to the compile:
Code:

    gcc -o invoke \
    -I/usr/local/j2sdk1.4.2_01/include \
    -I/usr/local/j2sdk1.4.2_01/include/linux \
    -L/usr/local/j2sdk1.4.2_01/jre/lib/i386 \
    -ljava \
    invoke.c

The first error from that attempt is "/usr/lib/gcc-lib/i386-slackware-linux/3.2.2/../../../../
i386-slackware-linux/bin/ld: warning: libjvm.so, needed by /usr/local/j2sdk1.4.2_01/jre/lib/i386/libjava.so, not found"

So I find where libjvm.so is located and add that to the compile:
Code:

    gcc -o invoke \
    -I/usr/local/j2sdk1.4.2_01/include \
    -I/usr/local/j2sdk1.4.2_01/include/linux \
    -L/usr/local/j2sdk1.4.2_01/jre/lib/i386 \
    -L/usr/local/j2sdk1.4.2_01/jre/lib/i386/server \
    -ljava \
    invoke.c

The first error from that attempt is STILL "/usr/lib/gcc-lib/i386-slackware-linux/3.2.2/../../../../i386-slackware-linux/bin/ld: warning: libjvm.so, needed by /usr/local/j2sdk1.4.2_01/jre/lib/i386/libjava.so, not found"

So I spend a while to find out how Linux handles libraries, and decide to add the two library directories to /etc/ld.so.conf and run /sbin/ldconfig. Then I try to compile using the same compile command as before:
Code:


    gcc -o invoke \
    -I/usr/local/j2sdk1.4.2_01/include \
    -I/usr/local/j2sdk1.4.2_01/include/linux \
    -L/usr/local/j2sdk1.4.2_01/jre/lib/i386 \
    -L/usr/local/j2sdk1.4.2_01/jre/lib/i386/server \
    -ljava \
    invoke.c

Great! No errors! So let's see if this thing runs:

Code:

./invoke
Now I get the following error: "./invoke: error while loading shared libraries: libjava.so: cannot open shared object file: No such file or directory"

I confirm that libjava.so file is in /usr/local/j2sdk1.4.2_01/jre/lib/i386/ and that my /etc/ld.so.conf is correct:

Code:

    /usr/local/lib
    /usr/X11R6/lib
    /usr/i386-slackware-linux/lib
    /opt/kde/lib
    /usr/local/j2sdk1.4.2_01/jre/lib/i386
    /usr/local/j2sdk1.4.2_01/jre/lib/i386/server

I decide to look at the shared library dependencies of invoke:

Code:

ldd invoke
This gives me:

Code:

    libjava.so => not found
    libc.so.6 => /lib/libc.so.6 (0x4001e000)
    libjvm.so => /usr/local/j2sdk1.4.2_01/jre/lib/i386/server/libjvm.so (0x40151000)
    /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
    libnsl.so.1 => /lib/libnsl.so.1 (0x4076e000)
    libm.so.6 => /lib/libm.so.6 (0x40783000)
    libdl.so.2 => /lib/libdl.so.2 (0x407a6000)
    libpthread.so.0 => /lib/libpthread.so.0 (0x407a9000)

Notice that libjava.so is not found even though it is in /usr/local/j2sdk1.4.2_01/jre/lib/i386/ (which is in my /etc/ld.so.conf and also indicated to the compiler using the -L flag.)

What am I missing????

Thanks!

Update: some additional information. When I use ldd to examine libjava.so it says it cannot find libverify.so even though libverify.so is in the same directory as libjvm.so:

Code:

        libjvm.so => /usr/local/j2sdk1.4.2_01/jre/lib/i386/server/libjvm.so (0x4002a000)
        libverify.so => not found
        libnsl.so.1 => /lib/libnsl.so.1 (0x40648000)
        libdl.so.2 => /lib/libdl.so.2 (0x4065d000)
        libc.so.6 => /lib/libc.so.6 (0x40660000)
        libm.so.6 => /lib/libm.so.6 (0x40793000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x407b6000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)

When I use ldd to examine libverify.so, everything looks fine:

Code:

        libjvm.so => /usr/local/j2sdk1.4.2_01/jre/lib/i386/server/libjvm.so (0x4001a000)
        libc.so.6 => /lib/libc.so.6 (0x40638000)
        libnsl.so.1 => /lib/libnsl.so.1 (0x4076b000)
        libm.so.6 => /lib/libm.so.6 (0x40780000)
        libdl.so.2 => /lib/libdl.so.2 (0x407a3000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x407a6000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)



All times are GMT -5. The time now is 05:11 PM.