JNI-找不到本机库 [英] JNI - Cannot find native library
问题描述
我有一个用于C ++本机库的JNI包装器.当我尝试在Java代码中加载库时,看到以下异常:
I have a JNI wrapper for a C++ native library. When I try to load the library in my Java code, I see the following exception:
java.lang.UnsatisfiedLinkError: no Foo in java.library.path
我这样加载库:
System.loadLibrary("Foo");
我将java.library.path设置如下:
I set java.library.path as follow:
java.library.path = /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib
我在JVM选项中添加了-XshowSettings:properties
,并确认是否按上述设置了java.library.path.
I added -XshowSettings:properties
to the JVM options and confirmed that the java.library.path is set as shown above.
这是文件系统上的库.so:
Here's the library .so on the filesystem:
$ l /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/libFoo.so
-rwxr-xr-x 1 root wheel 448K 29 Oct 14:23 /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/libFoo.so
环境信息:
java.version = 1.7.0_40
os.arch = x86_64
os.name = Mac OS X
os.version = 10.10
那我为什么不能加载库?
So why can't I load the library?
推荐答案
在Mac OS X上,JDK不会在路径中搜索以.so
结尾的文件或.dylib
或.jnilib
以外的任何文件.我们需要确保本机库的文件名以.dylib
或.jnilib
结尾.
On Mac OS X, the JDK will not search the path for files ending in .so
, or anything else than .dylib
or .jnilib
. We need to make sure filenames of native libraries end with .dylib
or .jnilib
.
这篇关于JNI-找不到本机库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!