jeudi 5 mars 2015

java.lang.UnsatisfiedLinkError when using JNI on ubuntu



java.lang.UnsatisfiedLinkError when using JNI.


My Testing Environment:



Ubuntu 12.04/64-bit

JDK 1.7

gcc (Ubuntu/Linaro 4.6.3-1ubuntu5)



This is my java source: public class HelloJNI { static { //System.loadLibrary("libHelloJNI"); }



private native void sayHello() ;

public static void main(String[] args){
//System.getProperties().list(System.out);
String lib_path = System.getProperty("java.library.path");
System.out.println("java.library.path=" + lib_path);

System.loadLibrary("libHelloJNI");

HelloJNI myJNI = new HelloJNI();
myJNI.sayHello();
}
}


This is my Makefile:



JNI_INC=-I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/linux"

JNI_LIB=libHelloJNI.so
JNI_OUT=$(JNI_LIB) HelloJNI.h HelloJNI.class
CFLAGS= $(JNI_INC) -fPIC -shared

all: $(JNI_OUT)

HelloJNI.h: HelloJNI.class
javah -jni HelloJNI

$(JNI_LIB): HelloJNI.c HelloJNI.h
gcc $(CFLAGS) -o $@ HelloJNI.c

HelloJNI.class: HelloJNI.java
javac HelloJNI.java

run:
java HelloJNI
#java -Djava.library.path=. HelloJNI

clean:
rm $(JNI_OUT)


When i run the java app, the OLD problem occurs:



Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 java.library.path=.:/home/mancook/cook/work/StSoftware/src/java/StTestJni/http://tutor01_HelloJNI:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

Exception in thread "main" java.lang.UnsatisfiedLinkError: no libHelloJNI in java.library.path

at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)

at java.lang.Runtime.loadLibrary0(Runtime.java:849)

at java.lang.System.loadLibrary(System.java:1088)

at HelloJNI.main(HelloJNI.java:22)

make: *** [run] Error 1



I have googled internet for this problem and find that it is an OLD question. But I CANNOT find any method to fix my problem!! Hope someone can help me. Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire