From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28646 invoked by alias); 27 May 2009 08:48:24 -0000 Received: (qmail 28627 invoked by uid 22791); 27 May 2009 08:48:20 -0000 X-SWARE-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL,BAYES_50,J_CHICKENPOX_46,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 27 May 2009 08:48:12 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n4R8mAFP007920; Wed, 27 May 2009 04:48:10 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n4R8m97t001562; Wed, 27 May 2009 04:48:09 -0400 Received: from zebedee.pink (vpn-12-18.rdu.redhat.com [10.11.12.18]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n4R8m6nr006171; Wed, 27 May 2009 04:48:07 -0400 Message-ID: <4A1CFE46.8040109@redhat.com> Date: Wed, 27 May 2009 08:48:00 -0000 From: Andrew Haley User-Agent: Thunderbird 2.0.0.17 (X11/20081009) MIME-Version: 1.0 To: Vaijayanthi Mala Suresh CC: java@gcc.gnu.org Subject: Re: Invoking JNI function using gcj References: <6f1633170905270134m29a652d6g270a7fb97833bf05@mail.gmail.com> In-Reply-To: <6f1633170905270134m29a652d6g270a7fb97833bf05@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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/msg00068.txt.bz2 Vaijayanthi Mala Suresh wrote: > 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 You can't mix JNI and CNI like this. Don't use the -jni commands. > 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? It doesn't even compile for me. Your cppstartup.cpp is incomplete. Andrew.