> Does "file libHelloWorld.so" correctly identify the file as a shared
> object?
[quoted text clipped - 3 lines]
> find them, such as /lib, /usr/lib or other directories mentioned in
> /etc/ld.so.conf?
I went ahead and tried out the example on Roedy's site (mindprod).
Sadly, the results were the same. Here is every step:
sprotsman@cressida:~/workspace> mkdir -p Glue/com/mindprod/JNIexper
sprotsman@cressida:~/workspace> cd Glue
Copy Java source from web page and inserted into Glue/com/mindprod/
JNIexper/Glue.java.
sprotsman@cressida:~/workspace/Glue> javac -classpath . com/mindprod/
JNIexper/Glue.java
sprotsman@cressida:~/workspace/Glue> javah -jni -o Glue.h
com.mindprod.JNIexper.Glue
Copy C source from web page and inserted into Glue/Glue.c. Changed
"#include <windows.h>" to "#include <stdio.h>".
sprotsman@cressida:~/workspace/Glue> gcc -fPIC -D_REENTRANT -I/usr/lib/
SunJava2-1.4.2/include -I/usr/lib/SunJava2-1.4.2/include/linux -c
Glue.c
sprotsman@cressida:~/workspace/Glue> gcc -shared Glue.o -o
libGlue.sosprotsman@cressida:~/workspace/Glue> java -classpath .
com.mindprod.JNIexper.Glue
sprotsman@cressida:~/workspace/Glue> java -Djava.library.path=. -
classpath . com.mindprod.JNIexper.Glue
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/
sprotsman/workspace/Glue/libGlue.so: /home/sprotsman/workspace/Glue/
libGlue.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 com.mindprod.JNIexper.Glue.<clinit>(Glue.java:10)
To answer Gordon's questions:
Contents of current working directory:
sprotsman@cressida:~/workspace/Glue> ls -F
com/ Glue.c Glue.h Glue.o libGlue.so
sprotsman@cressida:~/workspace/Glue> ldd libGlue.so
libc.so.6 => /lib64/tls/libc.so.6 (0x0000002a9567c000)
/lib64/ld-linux-x86-64.so.2 (0x000000552aaaa000)
sprotsman@cressida:~/workspace/Glue> file libGlue.so
libGlue.so: ELF 64-bit LSB shared object, AMD x86-64, version 1
(SYSV), not stripped
Gordon Beaton - 29 Nov 2007 08:42 GMT
> To answer Gordon's questions:
>
[quoted text clipped - 10 lines]
> libGlue.so: ELF 64-bit LSB shared object, AMD x86-64, version 1
> (SYSV), not stripped
You didn't answer the most important question: is your working
directory part of LD_LIBRARY_PATH, or java.library.path?
I see you've built a 64-bit library. Are you using a 64-bit JVM?
What happens when you use
System.load("/complete/path/to/libHelloWorld.so");
instead of
System.loadLibrary("HelloWorld")?
/gordon
--
joerg - 29 Nov 2007 12:01 GMT
> ...
>
> sprotsman@cressida:~/workspace/Glue> file libGlue.so
> libGlue.so: ELF 64-bit LSB shared object, AMD x86-64, version 1
> (SYSV), not stripped
Just a guess:
We had similar problems on other platforms when trying to
use 64-bit libraries with 32-bit java/jvm binaries or vice versa.
I don't know if this could happen also in your environment, but it's
worth a try. (Can 64-bit Linux run 32-bit programs on AMD?)
Joerg
Nigel Wade - 29 Nov 2007 12:11 GMT
>> ...
>>
[quoted text clipped - 9 lines]
> I don't know if this could happen also in your environment, but it's
> worth a try. (Can 64-bit Linux run 32-bit programs on AMD?)
Yes, but you cannot mix them - a 32bit application cannot load a 64bit library,
and vice versa.
Although I have heard there is a mechanism which allows a 64bit Firefox to load
the 32bit Java and Swing plugins, so that might not be entirely accurate.

Signature
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
protoplasm - 29 Nov 2007 21:45 GMT
Nigel, joerg,
That came to mind too. I tried compiling the libHelloWorld.so with -
m32 and that seems to have done the trick.
$ gcc -m32 -fPIC -D_REENTRANT -I/usr/lib/SunJava2-1.4.2/include -I/usr/
lib/SunJava2-1.4.2/include/linux -c HelloWorld.c
$ gcc -m32 -shared HelloWorld.o -o libHelloWorld.so
Running the Java app:
$ java -Djava.library.path=. HelloWorld
Hello World!
Yay!
Roedy Green - 30 Nov 2007 11:45 GMT
On Thu, 29 Nov 2007 00:33:26 -0800 (PST), protoplasm
<sprotsman@gmail.com> wrote, quoted or indirectly quoted someone who
said :
>I went ahead and tried out the example on Roedy's site (mindprod).
>Sadly, the results were the same. Here is every step:
the example on my site is for windows.
Use Wassup to find out what directories it is scanning for *.so native
code.
see http://mindprod.com/applet/wassup.html
look in the restricted properties for:
java.library.path = F:\Program Files\Opera 9.5
beta;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;E:\ENV;E:\SYS;C:\Windows;C:\Windows\SYSTEM32;C:\Windows\SYSTEM32\WBEM;F:\program
files\jet5.0-pro\bin;F:\program
files\jpsoft\4NT8;E:\apache-ant-1.7.0\bin\;E:\vslick\win;E:\Program
Files\Java\jdk1.6.0_03\bin;C:\Program Files\QuickTime\QTSystem\
These are all the places it will look. The current directory is not
necessarily in that list, though in my case it is.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com