building proper .so file for JNI
Tom Tromey
tromey@redhat.com
Fri Feb 23 12:53:00 GMT 2001
>>>>> "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 Gcc-bugs
mailing list