JNI on Redhat Linux

D

Douglas Jordan

I followed Sun's JNI tutorial and created a HelloWorld program like
theirs. It works just fine using the built-in gcj java, but does not
work using Sun's official java 1.4.2_08 distribution.

In other words:
[~/jni-test]$ /opt/java/j2sdk1.4.2_08/jre/bin/java
-Djava.library.path=. HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError:
/export/home/djordan/jni-test/libhello.so:
/export/home/djordan/jni-test/libhello.so: cannot open shared object
file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1586)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1511)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at HelloWorld.<clinit>(HelloWorld.java:5)
[~/jni-test]$ /usr/bin/java -Djava.library.path=. HelloWorld
Hello world!
[~/jni-test]$

I'm using gcc (GCC) 3.4.3 20041212 (Red Hat 3.4.3-9.EL4) to build with:
gcc -fPIC -shared -I/opt/java/j2sdk1.4.2_08/include
-I/opt/java/j2sdk1.4.2_08/include/linux HelloWorldImpl.c -o libhello.so

When I do ldd libhello.so I get:
libc.so.6 => /lib64/tls/libc.so.6 (0x0000002a95683000)
/lib64/ld-linux-x86-64.so.2 (0x000000552aaaa000)

My project has a requirement to use Sun's official Java distribution.
Any ideas?

Thanks.
 
G

Gitta Zahn

Douglas said:
I followed Sun's JNI tutorial and created a HelloWorld program like
theirs. It works just fine using the built-in gcj java, but does not
work using Sun's official java 1.4.2_08 distribution.

[~/jni-test]$ /opt/java/j2sdk1.4.2_08/jre/bin/java
-Djava.library.path=. HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError:
/export/home/djordan/jni-test/libhello.so:
/export/home/djordan/jni-test/libhello.so: cannot open shared object
file: No such file or directory
I'm using gcc (GCC) 3.4.3 20041212 (Red Hat 3.4.3-9.EL4) to build with:
gcc -fPIC -shared -I/opt/java/j2sdk1.4.2_08/include
-I/opt/java/j2sdk1.4.2_08/include/linux HelloWorldImpl.c -o libhello.so

When I do ldd libhello.so I get:
libc.so.6 => /lib64/tls/libc.so.6 (0x0000002a95683000)
/lib64/ld-linux-x86-64.so.2 (0x000000552aaaa000)

Did you tried it on an AMD64 (x86_64) system ?
See http://java.sun.com/j2se/1.4.2/install.html
Sun supports the 64 bit Java Linux only under 64-bit Intel Itanium 2.

I tried this under Suse 9.2, x86_64, JDK 1.4.2_06 (32 bit version).
When I compile/link the native library I got some linkage errors,
that the libjvm.so is ignored:

gcc CallGnu.o -L$JAVA_HOME/jre/lib/i386/server -ljvm -shared -o
libCallGnu.so
/usr/lib64/gcc-lib/x86_64-suse-linux/3.3.4/../../../../x86_64-suse-linux/bin/ld:
skipping incompatible
/usr/lib/jvm/java-1.4.2-sun/jre/lib/i386/server/libjvm.so when searching
for -ljvm
/usr/lib64/gcc-lib/x86_64-suse-linux/3.3.4/../../../../x86_64-suse-linux/bin/ld:
cannot find -ljvm
collect2: ld returned 1 exit status

When I compile/link the native library under another 32 bit Linux system
and later execute the whole program under the 64 bit Linux/ 32bit Java
works.


Gitta
 
D

Douglas Jordan

Gitta said:
When I compile/link the native library under another 32 bit Linux system
and later execute the whole program under the 64 bit Linux/ 32bit Java
works.

Thanks for the response. You are correct, I using an x86_64 system and
when I tried your gcc command I got the same incompatibility error. Is
there any way to force gcc to use 32bit libs instead?
 
D

Douglas Jordan

Douglas said:
Thanks for the response. You are correct, I using an x86_64 system and
when I tried your gcc command I got the same incompatibility error. Is
there any way to force gcc to use 32bit libs instead?

Uh nevermind. I just added a -m32 flag to the gcc line and that did a
trick. Maybe next time I should read the gcc man page BEFORE posting...
=)

Thanks, everything's working now!
 
N

Nigel Wade

Douglas said:
Uh nevermind. I just added a -m32 flag to the gcc line and that did a
trick. Maybe next time I should read the gcc man page BEFORE posting...
=)

Thanks, everything's working now!

You could try the 1.5/5.0 SDK which has an AMD64 RPM. I've not tried it
myself, but I would expect it to work as the 64bit Linux platforms which
Sun sells are Opteron based.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top