This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Getting started with GCJ



Michael J McGonagle writes:

> Anyway, is there a REALLY good reason to upgrade? Mandrake uses
> version 2.96 of gcc, and I had heard that this version of the
> compiler is not the best.

gcj and libgcj are getting better everyday. You might find very soon
that in order to do something useful with gcj, 3.0.x is a good choice
(comes in the form of a RPM for an better install experience) but the
current tree is probably better. Sooner or later you're going to run
into a bug (most likely a compiler bug first) that'll require you to
upgrade. You can probably postpone until then.

> So what it comes down to, is how do you compile two classes that are
> mutually dependant on each other?

Provided that the dependency is legal (that there's not cyclic
inheritance for instance) you just go by invoking the compiler
separately on the files. The linking phase will determine if the
(mutual) dependencies can be satisfied. For example:

  apbianco@venonat[/tmp]: cat A.java 
  class A {static B foo;}
  apbianco@venonat[/tmp]: cat B.java 
  class B {static A foo;}
  apbianco@venonat[/tmp]: cat C.java 
  class C {
    public static void main (String[] arg)
    {
      System.out.println (new A().toString());
    }
  }
  apbianco@venonat[/tmp]: gcj -c A.java 
  apbianco@venonat[/tmp]: gcj -c B.java 
  apbianco@venonat[/tmp]: gcj -c C.java 
  apbianco@venonat[/tmp]: gcj A.o B.o C.o -o C --main=C
  apbianco@venonat[/tmp]: ./C
  A@8065fd8

A.java and B.java depends on each other. They're built separately. C
needs A which needs B. If you fail to instruct the linker that it is
the case, you'll get a link error:

  apbianco@venonat[/tmp]: gcj A.o C.o -o C --main=C     
  A.o: In function `A::A()':
  /tmp/A.java:1: undefined reference to `B::class$'
  collect2: ld returned 1 exit status

Is that answering your question?

> Also, does anyone know of a simple tool that can handle the compilation
> of a complex project? Do most people use Makefile's?

Yes. Or you can automate the Makefile generation using automake. In
which case our Makefile looks like a list of files to compile and
other control things, like a variable used to tell how gcj should be
invoked.

./A


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]