How to link a native library that jni method needs in Linux?
843829Dec 8 2002 — edited Dec 16 2002I'm trying to convert a simple driver using JNI to java in Linux. The driver uses native methods (written in C) that are implemented in a static library eth.a, so I don't have a source code for these methods. Everything works fine when pure C-code program is used, however when I'm trying to use java-program where native methods (which naturally need these driver-functions in eth.a) I got a following error:
LibPath= /usr/kahvi/ioapi/
Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/kahvi/ioapi/libEthDriver.so: /usr/kahvi/ioapi/libEthDriver.so: undefined symbol: DDI_DevOpenNode
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1354)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1278)
at java.lang.Runtime.loadLibrary0(Runtime.java:466)
at java.lang.System.loadLibrary(System.java:771)
at EthernetDriver.<clinit>(EthernetDriver.java:89)
DDI_DevOpenNode is the first method that program uses from eth.a -library.
I have tried several different linking option such as:
gcc -o libEthDriver.so -DLINUX -DETH_UNIX -shared -Wl,-soname,libEthDriver.so -I/usr/jdk1.2.2/include -I/usr/jdk1.2.2/include/linux/ -I/usr/kahvi/ioapi/inc/ EthernetDriver.c -static -lc
eth.a is located in /inc directory and LD_LOAD_LIBRARY is used properly.
If I include eth.a directly to compilation options (which I'm not sure how to do), the error message is following:
LibPath= /usr/kahvi/ioapi/
Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/kahvi/ioapi/libEthDriver.so: eth.a: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1354)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1278)
at java.lang.Runtime.loadLibrary0(Runtime.java:466)
at java.lang.System.loadLibrary(System.java:771)
at EthernetDriver.<clinit>(EthernetDriver.java:89)
So the basic problem is quite simple, how to implement a JNI-method that uses a functions implemented in another library?
Any help is very much appreciated, because I have tried to solve this a few days and I don't have clues how to move on.
-ML