From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13068 invoked by alias); 10 Jun 2009 10:16:07 -0000 Received: (qmail 13059 invoked by uid 22791); 10 Jun 2009 10:16:06 -0000 X-SWARE-Spam-Status: No, hits=0.1 required=5.0 tests=AWL,BAYES_50,J_CHICKENPOX_43,J_CHICKENPOX_44,J_CHICKENPOX_53,J_CHICKENPOX_82,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, 10 Jun 2009 10:15:58 +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 n5AAFuJj007443; Wed, 10 Jun 2009 06:15:56 -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 n5AAFtpF028028; Wed, 10 Jun 2009 06:15:55 -0400 Received: from zebedee.pink (vpn-13-1.rdu.redhat.com [10.11.13.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n5AAFsjN028894; Wed, 10 Jun 2009 06:15:54 -0400 Message-ID: <4A2F87D9.5040207@redhat.com> Date: Wed, 10 Jun 2009 10:16:00 -0000 From: Andrew Haley User-Agent: Thunderbird 2.0.0.17 (X11/20081009) MIME-Version: 1.0 To: David Michel CC: java@gcc.gnu.org Subject: Re: How to convert a jar into so file and use it ? References: In-Reply-To: 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-06/txt/msg00031.txt.bz2 David Michel wrote: > > I have a very simple java test code that uses a public method called > 'coucou' of a external jar called 'Hello.jar' which contains the > package 'hello' and the public class 'Hello'. Here is the test code > Tool.java: > > import hello.Hello; > > public class Tool > { > public static void main(String[] args) > { > System.out.println("main program running"); > Hello.coucou(); > } > } > > which I would usually compile, with the following commands: > > $ gcj -O0 -g0 -C Tool.java --classpath=./:extern/Hello.jar > $ gij -cp .:extern/Hello.jar Tool > > Now if I want to compile Tool.java natively with gcj, what do I need to do ? > > I can create the shared library from the jar like this: > $ gcj -O0 -g0 -shared -findirect-dispatch -fjni -fPIC > extern/Hello.jar -o extern/Hello.jar.so > > > I can then compile Tool.java into Tool.o with: > $ gcj -O0 -g0 --classpath=./:extern/Hello.jar -c Tool.java -o Tool.o > > (altough this is using the jar and not the so ??) > > But then, I'm stuck with creating the final executable, i.e. Tool.out You didn't provide the source code for hello.Hello. However, I'm guessing it's public class Hello { public static void coucou() { System.out.println("coucou"); } } $ gcj -C hello/Hello.java $ jar cf Hello.jar hello/Hello.class $ gcj -shared hello/Hello.class -o libhello.so -fpic $ gcj Tool.java -L. -lhello --classpath=.:hello/Hello.jar --main=Tool $ LD_LIBRARY_PATH=. ./a.out main program running coucou Or, with -findirect-dispatch $ gcj -shared hello/Hello.java -o libhello.so -fpic -findirect-dispatch $ gcj Tool.java -L. -lhello --classpath=.:hello/Hello.jar --main=Tool -findirect-dispatch Andrew.