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: Invoking JNI function using gcj


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


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