I had successfully compiled my Java application to native code on Linux, but linking it to make an executable was causing undefined reference errors.
Providing the Jar path seemed sufficient, so I was puzzled why it wasn't working. The obvious then dawned upon me: linking native code of course requires native libraries.
Here's how to do it.
You have to compile the imported Jars into .so libraries individually. Make sure to provide the Jars in the --classpath, both while compiling the libraries as while compiling your code.
An example, where I'm compiling the GNU crypto library to an object file:
gcj --classpath=source/:libs/gnu-crypto.jar -fjni -c libs/gnu-crypto.jar -o libs/gnu-crypto.o
Then compile the object file to a native library:
gcj -shared -fPIC -o libs/libgnu-crypto.o libs/gnu-crypto.o -o libs/libgnu-crypto.so
Finally, execute your executable through a shell script referencing the library path. For example:
#!/bin/sh export LD_LIBRARY_PATH=./libs/:$LD_LIBRARY_PATH exec ./MyJavaApp $*
|