This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Invoking JNI function using gcj
- From: Bryce McKinlay <bmckinlay at gmail dot com>
- To: Vaijayanthi Mala Suresh <vaijayanthimalas at gmail dot com>
- Cc: java at gcc dot gnu dot org
- Date: Wed, 27 May 2009 10:48:23 +0100
- Subject: Re: Invoking JNI function using gcj
- References: <6f1633170905270134m29a652d6g270a7fb97833bf05@mail.gmail.com>
On Wed, May 27, 2009 at 9:34 AM, Vaijayanthi Mala Suresh
<vaijayanthimalas@gmail.com> wrote:
> 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);
It looks like you're confusing JNI with CNI. You mentioned JNI and
used the "-jni" option to gcjh, but the C++ code you provided appears
to be CNI.
Bryce