Static executables

Geoff Strom stromgt@speakeasy.net
Tue Jan 31 19:25:00 GMT 2006


Creating "semi-static" GCJ binaries on Linux isn't impossible. The first
step is acquiring GCC/GCJ built with "--enable-static" so that you have
all the necessary .a files. Then compile your .jar files and other source
to object files:

# compile jar files
gcj -c my_jar.jar
gcj -fjni -c my_jni_using_jar.jar

# compile source
find src/myproject -type f -name "*.java" | xargs gcj -c -o main.o

Then link all of your .o files together. In order to get semi-static
linking to work you need to hide libgcj.so.

# hide libgcj
cd $GCC_HOME/lib
mv libgcj.so XXX_libgcj.so

# build executable
gcj -static-libgcc --main=org.mydomain.myproject.Main -s -o myproject *.o

As others have said, you will need to create so called "force include"
files in order to make sure that all of the classes your application
needs are linked into the final binary.

Other tricks may be needed as well, depending on your needs.

-Geoff





More information about the Java mailing list