From: David Daney <ddaney@caviumnetworks.com>
To: Vaijayanthi Mala Suresh <vaijayanthimalas@gmail.com>
Cc: java@gcc.gnu.org
Subject: Re: gcj: issue with run time library loading
Date: Thu, 21 May 2009 15:40:00 -0000 [thread overview]
Message-ID: <4A1575C4.9010104@caviumnetworks.com> (raw)
In-Reply-To: <6f1633170905210141u3861d1ffh112de85009d88271@mail.gmail.com>
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
prev parent reply other threads:[~2009-05-21 15:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-21 8:41 Vaijayanthi Mala Suresh
2009-05-21 15:40 ` David Daney [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A1575C4.9010104@caviumnetworks.com \
--to=ddaney@caviumnetworks.com \
--cc=java@gcc.gnu.org \
--cc=vaijayanthimalas@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).