线程“main”java中出现异常。lang.unsatifiedLinkError:java中没有数学。图书馆路径
我正在尝试用java运行cpp代码。但是得到这个错误:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no math in java.library.path
我试图在之后使用此命令将我的库链接到java.library.path
$ javac HelloJNI.java
$ java -Djava.library.path="/home/sneha/Videos/node-ffi-example/math.so" HelloJNI
但还是一样的错误
这是我的HelloJNI.java
文件
public class HelloJNI { // Save as HelloJNI.java
static{
System.loadLibrary("math"); // Load native library hello.dll (Windows) or libhello.so (Unixes)
// at runtime
// This library contains a native method called sayHello()
System.out.println(".so included");
}
// Declare an instance native method sayHello() which receives no parameter and returns void
private native int num();
// Test Driver
public static void main(String[] args) {
HelloJNI hj = new HelloJNI();
int num = hj.num(); // Create an instance and invoke the native method
System.out.println("Number: "+num);
}
}
请帮忙,谢谢
# 1 楼答案
试着用一个。而不是dll。(这对我有用)
# 2 楼答案
您必须确保使用目录位置:
而不是
另外,尝试使用一些现成的示例来熟悉
JNI
。例如:http://jnicookbook.owsiak.org/recipe-No-001/或直接转到源:https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo001