From: Vaijayanthi Mala Suresh <vaijayanthimalas@gmail.com>
To: java@gcc.gnu.org
Subject: Invoking JNI function using gcj
Date: Wed, 27 May 2009 08:34:00 -0000 [thread overview]
Message-ID: <6f1633170905270134m29a652d6g270a7fb97833bf05@mail.gmail.com> (raw)
I have written an HelloWorld.java as given below
public class HelloWorld {
public native void natPrint();
public HelloWorld()
{
System.out.println("Hello from constructor");
}
public void printline()
{
System.out.println("Hello from printline");
natPrint()
}
public static void main(String [] args) {
System.out.println("Hello from main");
HelloWorld ht = new HelloWorld();
ht.printline();
}
static
{
System.loadLibrary("HelloWorld");
}
}
I have compiled it with gcj as given below
gcj -c -fjni HelloWorld.java
gcj -C HelloWorld.java
gcjh HelloWorld
gcjh -jni HelloWorld -o HelloNative.h
gcjh -stubs -jni HelloWorld
g++ -I. -c HelloWorld.c natHelloWorld.o
gcj -shared natHelloWorld.o -o libHelloWorld.so
Copied the .so file into the folder as /lib and it set in LD_LIBRARY_PATH.
I have a cppstartup.cpp which does the JVM Initialization and has
invokes HelloWorld as given below
#include "HelloWorld.h"
using namespace java::lang;
try
{
JvCreateJavaVM(NULL);
JvAttachCurrentThread(NULL, NULL);
String *message = JvNewStringLatin1("Hello from C++");
JvInitClass(&System::class$);
System::out->println(message);
HelloWorld *ht = new HelloWorld();
ht->printline();
JvDetachCurrentThread();
}
catch (Throwable *t)
{
System::err->println(JvNewStringLatin1("Unhandled Java exception:"));
t->printStackTrace();
}
This throws an exception me "Unsatisfied Linker Error"
Can someone help me in this regard?
next reply other threads:[~2009-05-27 8:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-27 8:34 Vaijayanthi Mala Suresh [this message]
2009-05-27 8:48 ` Andrew Haley
2009-05-27 9:48 ` Bryce McKinlay
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=6f1633170905270134m29a652d6g270a7fb97833bf05@mail.gmail.com \
--to=vaijayanthimalas@gmail.com \
--cc=java@gcc.gnu.org \
/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).