Problem with C dynamic library with JNI

ChemAxon

Registered
I have a C program and can call it in JNI interface in Windows and Linux, but I can not make it work on (Intel based) Mac OSX 10.4 (Tiger). I`m using a makefile with the following C compiler and linker options.


In Windows the following options worked
compiler:
gcc -Wall -O3 -c -I${JAVA_HOME}\include
-I${JAVA_HOME}\include\win32
linker:
gcc -s -shared -Wl,--export-all-symbols -Wl,--kill-at

In Linux the following options worked
compiler:
gcc -Wall -O3 -c -I${JAVA_HOME}/include
-I${JAVA_HOME}/include/win32
linker:
gcc -s -shared

In Mac I`ve tried all options from above and have searched the net for the right code. With the following code the lib file is successfully created without any errors or warnings, but java still gives:
java.lang.UnsatisfiedLinkError: /Users/vertset/.chemaxon/lib/libinchi.jnilib:
at
java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1647)
...

The last options I`ve tried:
compiler:
gcc -g -I/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Headers -c -fno-common -O2 -pipe
linker:
gcc -dynamic -fno-common -O2 -pipe -flat_namespace -undefined suppress

I`ve also tried the options worked in Windows or Linux, but mos of them is unknown by the Mac. I!ve also tried g++ instead of gcc in the linker, and cc program instead of gcc, they had the same results. On the net some forums said that setting the LD_LIBRARY_PATH could work, but it is also uneffective.


Thank you for your help.
Peter Vadasz
Java programmer
ChemAxon Ltd.
pvadasz@chemaxon.hu
 
It looks like Java can't find the library you're trying to load since it compiles correctly. The correct way to set the library path is DYLD_LIBRARY_PATH, not LD_LIBRARY_PATH. Try setting that and see if it helps. Note, setting the path via $HOME/.profile or /etc/profile will only work from the Terminal.
 
I've set the DYLD_LIBRARY_PATH, but nothing changed at all. I do not think so that the problem is about the library path. In that case the java error message would tell it - on forums it is said.
Thanks for your quick answer.
 
Hi, did you ever figure out what your problem is? I am having a similar problem. I am certain that the library is being found in the path, I've debugged into the SDK code for System.loadLibrary() to find out. There is something that it doesn't like about the library itself. Deep inside that call it makes a call NativeLibrary.load() which is itself a native method. It is in here where my code fails with the UnsatisfiedLinkError.

For the record, heres the linker options I am building with (using Maven2 and the Mojo native plugin): nostartfiles -flat_namespace -static -framework JavaVM -dynamiclib

Thanks!
 
I believe I may have solved my problem. I tried your linker flags but also added -bundle. Everything linked and loaded (apparently) just fine after that.
 
Back
Top