This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

building proper .so file for JNI


Hello,

I have been reading mails from this list for a couple of days to try solve
my current issue, but to no avail.  So, if this is a repeat, I am sorry.  

All I'm trying to do is, compile a C++ file as a shared object and load that
from a Java class.  This is to be done on SunOS 5.6.  It appears to compile
everything and create the shared object just fine, but when I try to load
from my Java class, I get an exception.  I have tried using the
"System.loadLibrary" and "System.load" methods, but to no avail.  I have set
the LD_LIBRARY_PATH variable (although I don't think that matters with the
"System.load" command, does it?).  It's a simple HelloWorld example that
passes strings back and forth from the Java class to the C++ shared object.
The ".so" filename is libHello.so.  I read that I shouldn't create it with
the g++ command and instead use the gcc command with the -lgcc option.  So,
I am building the file with the following statements:

#create .o file
g++ -c -w -I$(JAVA_INCLUDE) -I$(JAVA_INCLUDE_SOLARIS) -o Hello.o Hello.C

#create .so file
gcc -o libHello.so -shared Hello.o -lgcc

When I try "System.loadLibrary("Hello");" I get the following exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no Hello in
java.library.path

I have set the java.library.path to point to my shared object but it still
didn't recognize the object.

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

All the documentation I read says if I get the above exception, it's because
the library doesn't exist.  Well, you'll have to take my word that after the
above compilations, this file does reside there.

Any suggestions?

Thanks,
Eric


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]