public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
* How to convert a jar into so file and use it ?
@ 2009-06-10  9:40 David Michel
  2009-06-10 10:16 ` Andrew Haley
  0 siblings, 1 reply; 7+ messages in thread
From: David Michel @ 2009-06-10  9:40 UTC (permalink / raw)
  To: java

Hello,

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

Any clues ?

Cheers
David

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to convert a jar into so file and use it ?
  2009-06-10  9:40 How to convert a jar into so file and use it ? David Michel
@ 2009-06-10 10:16 ` Andrew Haley
  2009-06-10 10:50   ` David Michel
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Haley @ 2009-06-10 10:16 UTC (permalink / raw)
  To: David Michel; +Cc: java

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to convert a jar into so file and use it ?
  2009-06-10 10:16 ` Andrew Haley
@ 2009-06-10 10:50   ` David Michel
  2009-06-10 11:06     ` Andrew Haley
  0 siblings, 1 reply; 7+ messages in thread
From: David Michel @ 2009-06-10 10:50 UTC (permalink / raw)
  To: Andrew Haley; +Cc: java

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 <aph@redhat.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.
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to convert a jar into so file and use it ?
  2009-06-10 10:50   ` David Michel
@ 2009-06-10 11:06     ` Andrew Haley
  2009-06-10 11:53       ` Vaijayanthi Mala Suresh
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Haley @ 2009-06-10 11:06 UTC (permalink / raw)
  To: David Michel; +Cc: java

David Michel wrote:
> 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 ?

The Hello.jar file is used at compile time to check the names and types
of all the classes you're going to use.  It's not used at runtime.

Andrew.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to convert a jar into so file and use it ?
  2009-06-10 11:06     ` Andrew Haley
@ 2009-06-10 11:53       ` Vaijayanthi Mala Suresh
  2009-06-10 12:10         ` Andrew Haley
  0 siblings, 1 reply; 7+ messages in thread
From: Vaijayanthi Mala Suresh @ 2009-06-10 11:53 UTC (permalink / raw)
  To: Andrew Haley; +Cc: David Michel, java

Hi All,

I also have the same requirement. Taking from David's example,  when i
tried to do the following

gcj -O0 -g0  --classpath=./:extern/mytest.jar  -c TestApp.java -o TestApp.o

It gives me the following error

TestApp.java:56: internal compiler error: in make_class_data, at
java/class.c:1600
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

Can you please let me know what is the reason for this error.

What am I doing wrong over here?

Thanks
Mala

On Wed, Jun 10, 2009 at 4:36 PM, Andrew Haley<aph@redhat.com> wrote:
> David Michel wrote:
>> 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 ?
>
> The Hello.jar file is used at compile time to check the names and types
> of all the classes you're going to use.  It's not used at runtime.
>
> Andrew.
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to convert a jar into so file and use it ?
  2009-06-10 11:53       ` Vaijayanthi Mala Suresh
@ 2009-06-10 12:10         ` Andrew Haley
  2009-06-10 12:23           ` David Michel
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Haley @ 2009-06-10 12:10 UTC (permalink / raw)
  To: Vaijayanthi Mala Suresh; +Cc: David Michel, java

Vaijayanthi Mala Suresh wrote:

> I also have the same requirement. Taking from David's example,  when i
> tried to do the following
> 
> gcj -O0 -g0  --classpath=./:extern/mytest.jar  -c TestApp.java -o TestApp.o
> 
> It gives me the following error
> 
> TestApp.java:56: internal compiler error: in make_class_data, at
> java/class.c:1600
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See <URL:http://gcc.gnu.org/bugs.html> for instructions.
> 
> Can you please let me know what is the reason for this error.
> 
> What am I doing wrong over here?

Try it without the : in the pathname.  Did you follow my example
exactly?

Andrew.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to convert a jar into so file and use it ?
  2009-06-10 12:10         ` Andrew Haley
@ 2009-06-10 12:23           ` David Michel
  0 siblings, 0 replies; 7+ messages in thread
From: David Michel @ 2009-06-10 12:23 UTC (permalink / raw)
  To: Andrew Haley; +Cc: Vaijayanthi Mala Suresh, java

My example test code + Andrew's commands worked like a charm for me...
David

2009/6/10 Andrew Haley <aph@redhat.com>:
> Vaijayanthi Mala Suresh wrote:
>
>> I also have the same requirement. Taking from David's example,  when i
>> tried to do the following
>>
>> gcj -O0 -g0  --classpath=./:extern/mytest.jar  -c TestApp.java -o TestApp.o
>>
>> It gives me the following error
>>
>> TestApp.java:56: internal compiler error: in make_class_data, at
>> java/class.c:1600
>> Please submit a full bug report,
>> with preprocessed source if appropriate.
>> See <URL:http://gcc.gnu.org/bugs.html> for instructions.
>>
>> Can you please let me know what is the reason for this error.
>>
>> What am I doing wrong over here?
>
> Try it without the : in the pathname.  Did you follow my example
> exactly?
>
> Andrew.
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-06-10 12:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-10  9:40 How to convert a jar into so file and use it ? David Michel
2009-06-10 10:16 ` Andrew Haley
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

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).