Java Reference
In-Depth Information
architectures 6 was being added. At some point, it was decided to rename
(reacronym?) gcc to mean “GNU Compiler Collection.”
Not too surprisingly, as Java emerged and gained popularity, it became
one of the languages supported by the GCC using a front end called gcj . 7 That
is what we'll be talking about here.
7.4
C OMPILING O UR S IMPLE A PPLICATION WITH GCJ
The basic form of gcj is
gcj [ options ...] [ codefile ...] [@ listfile ...] [ libraryfile ...]
We'll go over the options in a moment. For now, let's talk about the
various kinds of input files the compiler can process.
In the above command-line synopsis, codefile refers to a Java source
file, a compiled .class file (yes, gcj can convert already compiled Java byte-
codes into native binaries), or even a ZIP or JAR file. A filename prefixed with
the at-sign, @ , indicates that the file contains a list of filenames to be compiled.
That's the @ listfile entry in the command synopsis. Finally, zero or more
library files to link with may be specified on the command line. When you
specify them directly (as opposed to using the -l command-line option) you
must provide the full name of the library.
Like all the other Java compilers we have talked about so far, gcj supports
the notion of a classpath. It will look in the classpath for unknown classes refer-
enced by the classes you name to the compiler. Since gcj can read and compile
from .class and .jar files, you might think you could just make sure that
the JAR files from Sun or IBM Java SDK are on the gcj classpath and you
would be able to compile any Java program using any Java APIs. Alas, you
would be wrong. Why? Because the Java APIs are full of native methods,
and which methods are implemented in Java and which are native is not
documented anywhere.
6. A lot of people do not realize this, but gcc is a cross-compiler. Precompiled binaries do
not always support this, but if you build your compiler from source, you can use gcc to
compile code for any supported platform. For example, you can compile a program for a
PowerPC-based Macintosh on your Intel-based PC.
7. http://gcc.gnu.org/java/index.html
Search WWH ::




Custom Search