Why doesn't GCJ find the classes from my imported packages?
Asked Answered
E

1

7

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?

Exodontist answered 23/7, 2009 at 12:53 Comment(2)
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?Sheik
Tried with Sun JDK or OpenJDK? If either of them works, then it's just (again) a bug in GCJ.Sardis
G
7

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 $*
Glossotomy answered 20/1, 2010 at 15:47 Comment(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.Radiophotograph

© 2022 - 2024 — McMap. All rights reserved.