LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-20-2003, 10:36 PM   #1
eric.r.turner
Member
 
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint Debian Edition (LMDE)
Posts: 215

Rep: Reputation: 31
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)

Last edited by eric.r.turner; 10-21-2003 at 08:51 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need comparison - libjava for mozilla tw001_tw Slackware 1 02-08-2005 09:49 PM
when installing limewire cant find jvm random kid Linux - Newbie 13 08-03-2004 05:05 PM
Limewire + libjava.so not found on RH8???? Ice9 Linux - General 0 02-15-2003 01:48 PM
Java jre-1.3.1_02 can't find libjava.so after install rhammack Linux - Software 0 01-17-2002 09:39 PM
libjava.so not found! Gladiator Linux - General 3 12-05-2001 02:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration