13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

7.4 Compiling Our Simple <str<strong>on</strong>g>Applicati<strong>on</strong></str<strong>on</strong>g> with gcj181architectures 6 was being added. At some point, it was decided to rename(reacr<strong>on</strong>ym?) gcc to mean “GNU Compiler Collecti<strong>on</strong>.”Not too surprisingly, as Java emerged and gained popularity, it became<strong>on</strong>e of the languages supported by the GCC using a fr<strong>on</strong>t end called gcj. 7 Thatis what we’ll be talking about here.7.4COMPILING OUR SIMPLE APPLICATION WITH GCJThe basic form of gcj isgcj [opti<strong>on</strong>s...] [codefile...] [@listfile...] [libraryfile...]We’ll go over the opti<strong>on</strong>s in a moment. For now, let’s talk about thevarious kinds of input files the compiler can process.In the above command-line synopsis, codefile refers to a Java sourcefile, a compiled .class file (yes, gcj can c<strong>on</strong>vert already compiled Java bytecodesinto native binaries), or even a ZIP or JAR file. A filename prefixed withthe at-sign, @, indicates that the file c<strong>on</strong>tains a list of filenames to be compiled.That’s the @listfile entry in the command synopsis. Finally, zero or morelibrary files to link with may be specified <strong>on</strong> the command line. When youspecify them directly (as opposed to using the -l command-line opti<strong>on</strong>) youmust provide the full name of the library.Like all the other Java compilers we have talked about so far, gcj supportsthe noti<strong>on</strong> of a classpath. It will look in the classpath for unknown classes referencedby the classes you name to the compiler. Since gcj can read and compilefrom .class and .jar files, you might think you could just make sure thatthe JAR files from Sun or IBM Java SDK are <strong>on</strong> the gcj classpath and youwould be able to compile any Java program using any Java APIs. Alas, youwould be wr<strong>on</strong>g. Why? Because the Java APIs are full of native methods,and which methods are implemented in Java and which are native is notdocumented anywhere.6. A lot of people do not realize this, but gcc is a cross-compiler. Precompiled binaries d<strong>on</strong>ot always support this, but if you build your compiler from source, you can use gcc tocompile code for any supported platform. For example, you can compile a program for aPowerPC-based Macintosh <strong>on</strong> your Intel-based PC.7. http://gcc.gnu.org/java/index.html

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!