From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24111 invoked by alias); 10 Jun 2009 10:50:15 -0000 Received: (qmail 24102 invoked by uid 22791); 10 Jun 2009 10:50:14 -0000 X-SWARE-Spam-Status: No, hits=1.1 required=5.0 tests=AWL,BAYES_50,J_CHICKENPOX_43,J_CHICKENPOX_44,J_CHICKENPOX_53,J_CHICKENPOX_82,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail-fx0-f222.google.com (HELO mail-fx0-f222.google.com) (209.85.220.222) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 10 Jun 2009 10:50:08 +0000 Received: by fxm22 with SMTP id 22so732605fxm.8 for ; Wed, 10 Jun 2009 03:50:05 -0700 (PDT) MIME-Version: 1.0 Received: by 10.102.244.8 with SMTP id r8mr652089muh.22.1244631004834; Wed, 10 Jun 2009 03:50:04 -0700 (PDT) In-Reply-To: <4A2F87D9.5040207@redhat.com> References: <4A2F87D9.5040207@redhat.com> Date: Wed, 10 Jun 2009 10:50:00 -0000 Message-ID: Subject: Re: How to convert a jar into so file and use it ? From: David Michel To: Andrew Haley Cc: java@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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/msg00032.txt.bz2 Thanks ! But I'm a bit puzzled by this ...-L. -lhello --classpath=3D.:hello/Hello.jar... Why does it need both the libhello.so and the Hello.jar file ? David 2009/6/10 Andrew Haley : > 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 >> { >> =A0 =A0public static void main(String[] args) >> =A0 =A0{ >> =A0 =A0 =A0System.out.println("main program running"); >> =A0 =A0 =A0Hello.coucou(); >> =A0 =A0} >> } >> >> which I would usually compile, with the following commands: >> >> $ gcj -O0 -g0 =A0-C Tool.java --classpath=3D./: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 =A0-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 =A0--classpath=3D./:extern/Hello.jar =A0-c Tool.java -o To= ol.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. =A0However, I'm > guessing it's > > public class Hello > { > =A0public static void coucou() > =A0{ > =A0 =A0System.out.println("coucou"); > =A0} > } > > > =A0$ gcj -C hello/Hello.java > =A0$ jar cf Hello.jar hello/Hello.class > =A0$ gcj -shared hello/Hello.class -o libhello.so -fpic > =A0$ gcj Tool.java -L. -lhello --classpath=3D.:hello/Hello.jar --main=3DT= ool > =A0$ LD_LIBRARY_PATH=3D. ./a.out > main program running > coucou > > > Or, with -findirect-dispatch > > =A0$ gcj -shared hello/Hello.java -o libhello.so -fpic -findirect-dispatch > =A0$ gcj Tool.java -L. -lhello --classpath=3D.:hello/Hello.jar --main=3DT= ool -findirect-dispatch > > Andrew. >