Next: , Previous: Warnings, Up: Invoking gcj

1.5 Linking

To turn a Java application into an executable program, you need to link it with the needed libraries, just as for C or C++. The linker by default looks for a global function named main. Since Java does not have global functions, and a collection of Java classes may have more than one class with a main method, you need to let the linker know which of those main methods it should invoke when starting the application. You can do that in any of these ways:

These gij options relate to linking an executable:

This option is used when linking to specify the name of the class whose main method should be invoked when the resulting executable is run.
This option can only be used with --main. It defines a system property named name with value value. If value is not specified then it defaults to the empty string. These system properties are initialized at the program's startup and can be retrieved at runtime using the java.lang.System.getProperty method.
Create an application whose command-line processing is that of the gij command.

This option is an alternative to using --main; you cannot use both.

This option causes linking to be done against a static version of the libgcj runtime library. This option is only available if corresponding linker support exists.

Caution: Static linking of libgcj may cause essential parts of libgcj to be omitted. Some parts of libgcj use reflection to load classes at runtime. Since the linker does not see these references at link time, it can omit the referred to classes. The result is usually (but not always) a ClassNotFoundException being thrown at runtime. Caution must be used when using this option. For more details see: