6

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?

Daniel Rikowski
  • 66,219
  • 52
  • 237
  • 318
  • Have you tried actually including the jar file from Apache POI in the lib folder of the project instead of externally linking to it in the class path at compile time? – amischiefr Jul 23 '09 at 12:56
  • Tried with Sun JDK or OpenJDK? If either of them works, then it's just (again) a bug in GCJ. – BalusC Jan 20 '10 at 15:51

1 Answers1

5

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 $*
Paul Lammertsma
  • 35,234
  • 14
  • 128
  • 182
  • 1
    I just started using GCJ and found this answer extremely helpful. Just wanted to note that `-fPIC` is required on the first command as well from my experience so far. – reve_etrange Apr 07 '11 at 03:15