From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23195 invoked by alias); 27 May 2009 08:34:36 -0000 Received: (qmail 23185 invoked by uid 22791); 27 May 2009 08:34:34 -0000 X-SWARE-Spam-Status: No, hits=1.4 required=5.0 tests=AWL,BAYES_50,J_CHICKENPOX_46,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail-qy0-f126.google.com (HELO mail-qy0-f126.google.com) (209.85.221.126) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 27 May 2009 08:34:30 +0000 Received: by qyk32 with SMTP id 32so5776636qyk.0 for ; Wed, 27 May 2009 01:34:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.71.6 with SMTP id f6mr7475501vcj.16.1243413268180; Wed, 27 May 2009 01:34:28 -0700 (PDT) Date: Wed, 27 May 2009 08:34:00 -0000 Message-ID: <6f1633170905270134m29a652d6g270a7fb97833bf05@mail.gmail.com> Subject: Invoking JNI function using gcj From: Vaijayanthi Mala Suresh To: java@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact java-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-owner@gcc.gnu.org X-SW-Source: 2009-05/txt/msg00066.txt.bz2 I have written an HelloWorld.java as given below public class HelloWorld { =A0 =A0public native void natPrint(); =A0 =A0public HelloWorld() =A0 =A0{ =A0 =A0 =A0System.out.println("Hello from constructor"); =A0 =A0} =A0 =A0public void printline() =A0 =A0{ =A0 =A0 =A0System.out.println("Hello from printline"); =A0natPrint() =A0 =A0} =A0 =A0public static void main(String [] args) { =A0 =A0 =A0System.out.println("Hello from main"); =A0 =A0 =A0HelloWorld ht =3D new HelloWorld(); =A0 =A0 =A0ht.printline(); =A0 =A0} static { =A0System.loadLibrary("HelloWorld"); } =A0} 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; =A0 =A0 =A0 try =A0 =A0 =A0 { JvCreateJavaVM(NULL); JvAttachCurrentThread(NULL, NULL); =A0 =A0 =A0 String *message =3D JvNewStringLatin1("Hello from C++"); =A0 =A0 =A0 JvInitClass(&System::class$); =A0 =A0 =A0 System::out->println(message); =A0 HelloWorld *ht =3D new HelloWorld(); =A0 =A0 =A0 ht->printline(); =A0 =A0 =A0 JvDetachCurrentThread(); =A0 =A0 =A0 } =A0 =A0 =A0 catch (Throwable *t) =A0 =A0 =A0 { =A0 =A0 =A0 =A0 System::err->println(JvNewStringLatin1("Unhandled Java exce= ption:")); =A0 =A0 =A0 =A0t->printStackTrace(); =A0 =A0 =A0 } This throws an exception =A0me "Unsatisfied Linker Error" Can someone help me in this regard?