Question

I want to compile a small Java application to a Windows executable.

The application is very small, only a single main class, but it uses Apache POI.

When I compile it, everything works fine, as long as I put the POI Jar into the class path argument.

But when it comes to linking, GCJ cannot resolve the references the classes in the POI package. The messages are all like this:

undefined reference tp 'org::apache::poi:hssf:usermodel:HSSFWorkbook::class$'

What do I have to do in order to link my application?

Was it helpful?

Solution

You have to compile the imported Jars into .so libraries separately. 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:

gcj --classpath=source/:libs/gnu-crypto.jar -fjni -c libs/gnu-crypto.jar -o libs/gnu-crypto.o 
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 $*
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top