building proper .so file for JNI

Briley, Eric EBriley@sark.com
Fri Feb 23 14:11:00 GMT 2001


Sorry, I guess I left out some information. 
>Are you using JNI? Did you compile your Java code (the class with >native
methods) with -fjni?
Yes I am using JNI. (If it would help if I attatched the actual java and
c++ code, I could) No, I did not use the -fjni option when I compiled. But
when I tried (javac -fjni...), it said that is an invalid option. I am
running jdk1.2.2, and must use that. Here's what I do to compile and
execute everything(the HelloWorld.java has the native method definitions,
and my Tester.java tries to load the shared object):
javac -classpath $(BUILD_CLASSPATH) HelloWorld.java
javah -jni -classpath $(BUILD_CLASSPATH) HelloWorld
javac -classpath $(BUILD_CLASSPATH) Tester.java
$g++ -c -w -I$(JAVA_INCLUDE) -I$(JAVA_INCLUDE_SOLARIS) -o Hello.o Hello.C
$gcc -o libHello.so -shared Hello.o -lgcc
java -classpath $(BUILD_CLASSPATH) Tester
I tried your -fPIC suggestion in the g++ statement but I still get my
exceptions:
When I try "System.load("/home/dev_usr/brileye/temp_Jni/libHello.so");" I
get the following exception: 
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load
library: /home/dev_usr/brileye/temp_Jni/libHello.so
When I try "System.loadLibrary("Hello");" I get the following
exception: 
Exception in thread "main" java.lang.UnsatisfiedLinkError: no Hello in
java.library.path
>Did libgcj generate this error? That suprises me a bit.
>Runtime::_load just uses the error message from libltdl, which
>shouldn't refer to java.library.path.

No, as you may have noticed from above, I am running this all from my Tester
class. I get these exceptions at runtime from Java at the time of execution
of Tester. But, this worked fine with different compiling options for an
"aCC" compiler on a HP-UX box. Now, I am trying to convert to the g++
compiler on a Sun box. 
Thanks a lot,
Eric
-----Original Message-----
From: Tom Tromey
To: Briley, Eric
Cc: 'java@gcc.gnu.org'; 'gcc-bugs@gcc.gnu.org'
Sent: 2/23/01 4:04 PM
Subject: Re: building proper .so file for JNI
>>>>> "Eric" == Briley, Eric <EBriley@sark.com> writes:

Eric> All I'm trying to do is, compile a C++ file as a shared object
Eric> and load that from a Java class. This is to be done on SunOS
Eric> 5.6. It appears to compile everything and create the shared
Eric> object just fine, but when I try to load from my Java class, I
Eric> get an exception.
In the Subject you mention JNI. Are you using JNI? Did you compile
your Java code (the class with native methods) with -fjni?
Eric> I have set the LD_LIBRARY_PATH variable (although I don't think
Eric> that matters with the "System.load" command, does it?).
Yes, it does.
Eric> #create .o file
Eric> g++ -c -w -I$(JAVA_INCLUDE) -I$(JAVA_INCLUDE_SOLARIS) -o Hello.o
Hello.C
You might need -fPIC here.
Eric> When I try "System.loadLibrary("Hello");" I get the following
exception:
Eric> Exception in thread "main" java.lang.UnsatisfiedLinkError: no
Hello in
Eric> java.library.path
Did libgcj generate this error? That suprises me a bit.
Runtime::_load just uses the error message from libltdl, which
shouldn't refer to java.library.path.
Eric> Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't
load
Eric> library: /home/dev_usr/brileye/temp_Jni/libHello.so
Eric> All the documentation I read says if I get the above exception,
Eric> it's because the library doesn't exist.
At least in our implementation this error can also mean that the
shared library can't be loaded for other reasons, for instance if it
refers to symbols that aren't available.
Tom


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /