Why doesn't GCJ find the classes from my impor

2019-04-29 04:15发布

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?

标签: java linker gcj
1条回答
时光不老,我们不散
2楼-- · 2019-04-29 04:39

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 $*
查看更多
登录 后发表回答