From: Andrew Haley <aph@redhat.com>
To: David Michel <dmichel76@googlemail.com>
Cc: java@gcc.gnu.org
Subject: Re: How to convert a jar into so file and use it ?
Date: Wed, 10 Jun 2009 10:16:00 -0000 [thread overview]
Message-ID: <4A2F87D9.5040207@redhat.com> (raw)
In-Reply-To: <b5bf7a380906100239j478ed915scee4a008fd44e201@mail.gmail.com>
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.
next prev parent reply other threads:[~2009-06-10 10:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-10 9:40 David Michel
2009-06-10 10:16 ` Andrew Haley [this message]
2009-06-10 10:50 ` David Michel
2009-06-10 11:06 ` Andrew Haley
2009-06-10 11:53 ` Vaijayanthi Mala Suresh
2009-06-10 12:10 ` Andrew Haley
2009-06-10 12:23 ` David Michel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A2F87D9.5040207@redhat.com \
--to=aph@redhat.com \
--cc=dmichel76@googlemail.com \
--cc=java@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).