我看到很多人在 SO 中发布了这个问题。我已经浏览了这些帖子并尝试了建议的方法,但不幸的是无法帮助我解决问题。
这是我的问题:
public class runme {
static {
System.loadLibrary("example");
}
public static void main(String argv[]) {
System.out.println(example.fact(4));
}
}
错误:
anu@anu-desktop:~/Desktop/swigtest/new$ java runme
Exception in thread "main" java.lang.UnsatisfiedLinkError: no example in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at runme.<clinit>(runme.java:5)
Could not find the main class: runme. Program will exit.
示例库与runme.java位于同一路径。为什么我会收到此错误?我在 Ubuntu 操作系统上工作。
非常感谢任何可以帮助我解决此问题的帮助。
编辑:
我已附上我的文件 here
最佳答案
尽管 docs说库名称映射到实际系统库的方式取决于系统,根据我的经验,loadLibrary
的相对路径指的是工作 目录(之后检查所有其他定义的和系统相关的路径)。
如果不确定工作目录,请检查 System.getProperty("user.dir")
返回的内容。
关于Ubuntu 中的 java.lang.UnsatisfiedLinkError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11010070/