该问题困扰我很久了,我也在网上查了很久,遇到这个错误的很多,但网上提供的解决方法我都试过,还是不行,请各位分析一下,十分感谢:
我试过,运行时通过-D指定java.library.path,设置环境变量LD_LIBRARY_PATH,拷贝这个库文件到打印出的java.library.path所在目录,甚至把gcc改用g++编译库等都试过,没有效果。
我运行的环境是SuSE Linux,JDK1.6.0
java文件:
public class GetPid {
static {
System.out.println(System.getProperty("java.library.path"));
System.loadLibrary("testdll.so");
}
public native static int get();
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(System.getProperty("java.library.path"));
GetPid test = new GetPid();
System.out.println(test.get());
/*try{
System.in.read(new byte[10]);
}
catch(Exception ex){
ex.printStackTrace();
}*/
}
}
错误信息:
linux-z03057:~/workspace/CtoJavaTest # java GetPid
/home/z03057/src/jdk1.6.0/jre/lib/i386/client:/home/z03057/src/jdk1.6.0/jre/lib/i386:/home/z03057/src/jdk1.6.0/jre/../lib/i386:.:/home/z03057/src/jdk1.6.0/jre/lib/i386/client:/home/z03057/src/jdk1.6.0/jre/lib/i386:/lib:/usr/lib:/usr/java/packages/lib/i386:/lib:/usr/lib
Exception in thread "main" java.lang.UnsatisfiedLinkError: no testdll.so in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at GetPid.<clinit>(GetPid.java:5)
linux-z03057:~/workspace/CtoJavaTest # java -Djava.library.path=/usr/lib GetPid
/usr/lib
Exception in thread "main" java.lang.UnsatisfiedLinkError: no testdll.so in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at GetPid.<clinit>(GetPid.java:5)