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]
Other format: [Raw text]

Re: gcj: issue with run time library loading


Vaijayanthi Mala Suresh wrote:
Hi,

I am trying to use JNI calls using gcj.

Hello.java is the jave code having a native method.

gcj -c -fjni Hello.java -o MyApp.o
gcjh Hello -o MyApp.h
ar -rcs libHello.a MyApp.o

Hello.c contains the native code implementation
gcjh -jni Hello
g++ -c Hello.c
ar rcs libNative.a Hello.o


I have a test.cpp where I have initialized the JVM and I am trying to invoke a method in the Java code which inturn invokes the native method. I have linked the above libraries along with test.o

I am getting the following error

Unhandled Java exception:
java.lang.UnsatisfiedLinkError: natPrint
   <<No stacktrace available>>

Can anyone help me to resolve this problem.


JNI under gcj is just like JNI under Sun/OpenJDK. The JNI library must be compiled as a shared object.


Something like this:

g++ -fPIC -c Hello.c
g++ -shared -o Hello.so Hello.o

Then of course you need to use java.lang.System.loadLibrary() to load the library before calling any methods in it.

You will note that these are the *exact* same steps you would take if you were to use the library on Sun's JDK. You wouldn't even have to recompile the library.

David Daney


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