LWJGL native compilation with GCJ success

I managed to natively compile a game that uses LWJGL via GCJ for linux.

The steps for a full native compilation are:

  1. Compile lwjgl & jinput into object files using gcj
Neotokyo:/tmp/lwjgl# l
total 528
-rw-r--r-- 1 root root  26493 Feb  8 22:31 Shmup.java
-rw-r--r-- 1 root root 104782 Dec 18 22:05 jinput.jar
-rw-r--r-- 1 root root 396822 Dec 18 22:05 lwjgl.jar

Neotokyo:/tmp/lwjgl# gcj -c -fjni jinput.jar 
Neotokyo:/tmp/lwjgl# gcj -c -fjni lwjgl.jar -Ijinput.jar

Neotokyo:/tmp/lwjgl# l *.o
-rw-r--r-- 1 root root  730396 Feb  8 22:32 jinput.o
-rw-r--r-- 1 root root 3996880 Feb  8 22:34 lwjgl.o

jinput is needed because lwjgl references some jinput classes by name. If jinput is not included,
AOT compilation will break with undefined references even if jinput is unused by the project.

  1. Compile and link the application
Neotokyo:/tmp/lwjgl# gcj --main=Shmup Shmup.java jinput.o lwjgl.o -Ijinput.jar -Ilwjgl.jar
Neotokyo:/tmp/lwjgl# l a.out ; strip a.out; l a.out
-rwxr-xr-x 1 root root 4033104 Feb  8 22:36 a.out
-rwxr-xr-x 1 root root 2336820 Feb  8 22:37 a.out <-- final executable, contains lwjgl & jinput, size can be reduced to ~500kb with upx
  1. Create deployment archive
    Assuming that the target users do not have libgcj (libjava) installed, we must create a fully self-contained deployment archive
    that will execute with no problems. The users do not have to download and install anything.

In order to do that we have to ship the following libraries with the application. First libraries that are part of libgcj:
lib-gnu-java-awt-peer-gtk.so
libgcj.so.6
libgcjawt.so
libjawt.so
pr13212.so

Then, extra native libraries used by our program, in this case the lwjgl native ones:
liblwjgl.so

These files can be grouped in a separate directory lib within our package. Use of the LD_LIBRARY_PATH linux env variable
will ensure that they get loaded properly.

The final size of our self-contained 100% native lwjgl application package: 6 mb
Most of this comes from the size of libgcj which is 16mb by itself. This solution only works on linux for now because the awt implementation
of gcj (and classpath) currently only supports gtk/x11 peers. Windows, Cairo, QT peers are in their todo list.Once mingw
is updated to reflect the latest versions of classpath and gcj, cross-compilation of completely native windows lwjgl applications
will be a reality.

The promising part of this article is that libgcj follows the GPL license with an exception that allows linking
with proprietary code without tainting this code. This means that someone could hack libgcj to pieces, create a mini
library containing only needed functionality and further reduce the filesize of his deployment package. The license would only
require that these changes to (only) libgcj be made public.

Versions used:
GCJ version 4.0.3 20060121 (prerelease)
LWJGL 0.99

cool! - thanks for a guide - last time I looked into it I had some serious issues

hey this is very cool news and a very nice tutorial, thx

Have you performed some benchmark (HotSpot versus GCJ for example) ?
I would be very interested to have an estimation of the speed benefit given by gcj.

I doubt it would give any serious FPS improvements, but the startup time would be awsome I would guess.

I doubt it would give any serious FPS improvements

I doubt it would give any FPS improvements. The runtime information is missing and the garbage collection scheme is most likely less advanced.

But the startup time schould be better indeed.

edit: Keep in mind that this kind of thing isnt about performance. Its about solving distribution issues.