public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
* gcj: issue with run time library loading
@ 2009-05-21  8:41 Vaijayanthi Mala Suresh
  2009-05-21 15:40 ` David Daney
  0 siblings, 1 reply; 2+ messages in thread
From: Vaijayanthi Mala Suresh @ 2009-05-21  8:41 UTC (permalink / raw)
  To: java

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.

Thanks
Mala

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: gcj: issue with run time library loading
  2009-05-21  8:41 gcj: issue with run time library loading Vaijayanthi Mala Suresh
@ 2009-05-21 15:40 ` David Daney
  0 siblings, 0 replies; 2+ messages in thread
From: David Daney @ 2009-05-21 15:40 UTC (permalink / raw)
  To: Vaijayanthi Mala Suresh; +Cc: java

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-05-21 15:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-21  8:41 gcj: issue with run time library loading Vaijayanthi Mala Suresh
2009-05-21 15:40 ` David Daney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).