JNI-找不到本机库 [英] JNI - Cannot find native library

查看:86
本文介绍了JNI-找不到本机库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于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.

参考: https://developer.apple.com/library/mac/documentation/Java/Conceptual/Java14Development/05-CoreJavaAPIs/CoreJavaAPIs.html

这篇关于JNI-找不到本机库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆