main
members
work
about me
avatar
Paul(admin)
post

Compiling Java Jars to Linux native libraries

Post replyCan't edit post
Watch topicCan't delete post
Friday, January 22 2010, 12:49
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 $*

Rating:
Actions:Post replyWatch topic
No comments.Post reply

More updates

Click here to read more news items.
Members have extra privileges. You can login or register.
© 2005–2017 P. F. Lammertsma
No members currently online; 392 hits today by 111 unique users