Re: How to convert a jar into so file and use it ?

David Michel <[email protected]>
Newsgroups gmane.comp.gcc.java.devel
Message-ID <[email protected]>
Thanks !

But I'm a bit puzzled by this

...-L. -lhello --classpath=.:hello/Hello.jar...

 Why does it need both the libhello.so and the Hello.jar file ?

David


2009/6/10 Andrew Haley <[email protected]>:
> 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.
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.