From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14271 invoked by alias); 21 May 2009 15:40:06 -0000 Received: (qmail 14225 invoked by uid 22791); 21 May 2009 15:40:05 -0000 X-SWARE-Spam-Status: No, hits=-0.6 required=5.0 tests=AWL,BAYES_50,J_CHICKENPOX_52,J_CHICKENPOX_54 X-Spam-Check-By: sourceware.org Received: from mail3.caviumnetworks.com (HELO mail3.caviumnetworks.com) (12.108.191.235) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 21 May 2009 15:40:00 +0000 Received: from exch4.caveonetworks.com (Not Verified[192.168.16.23]) by mail3.caviumnetworks.com with MailMarshal (v6,2,2,3503) id ; Thu, 21 May 2009 11:39:44 -0400 Received: from exch4.caveonetworks.com ([192.168.16.23]) by exch4.caveonetworks.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 21 May 2009 08:39:48 -0700 Received: from dd1.caveonetworks.com ([64.169.86.201]) by exch4.caveonetworks.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 21 May 2009 08:39:48 -0700 Message-ID: <4A1575C4.9010104@caviumnetworks.com> Date: Thu, 21 May 2009 15:40:00 -0000 From: David Daney User-Agent: Thunderbird 2.0.0.21 (X11/20090320) MIME-Version: 1.0 To: Vaijayanthi Mala Suresh CC: java@gcc.gnu.org Subject: Re: gcj: issue with run time library loading References: <6f1633170905210141u3861d1ffh112de85009d88271@mail.gmail.com> In-Reply-To: <6f1633170905210141u3861d1ffh112de85009d88271@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed 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/msg00053.txt.bz2 Vaijayanthi Mala Suresh wrote: > Hi, > > I am trying to use JNI calls using gcj. > > Hello.java is the jave code having a native method. > > gcj -c -fjni Hello.java -o MyApp.o > gcjh Hello -o MyApp.h > ar -rcs libHello.a MyApp.o > > Hello.c contains the native code implementation > gcjh -jni Hello > g++ -c Hello.c > ar rcs libNative.a Hello.o > > > I have a test.cpp where I have initialized the JVM and I am trying to > invoke a method in the Java code which inturn invokes the native > method. I have linked the above libraries along with test.o > > I am getting the following error > > Unhandled Java exception: > java.lang.UnsatisfiedLinkError: natPrint > <> > > Can anyone help me to resolve this problem. > JNI under gcj is just like JNI under Sun/OpenJDK. The JNI library must be compiled as a shared object. Something like this: g++ -fPIC -c Hello.c g++ -shared -o Hello.so Hello.o Then of course you need to use java.lang.System.loadLibrary() to load the library before calling any methods in it. You will note that these are the *exact* same steps you would take if you were to use the library on Sun's JDK. You wouldn't even have to recompile the library. David Daney