JNA UnsatisfiedLinkError,但 jna.library.path 已设置
我正在使用以下代码在 JNA 中加载 dll(省略了不相关的代码):
public class JNAMain {
public interface PointShapeBuffer extends Library { ... }
public static void main(String[] args){
System.setProperty("jna.library.path", "c:\\jnadll");
System.setProperty("java.library.path", "c:\\jnadll");
PointShapeBuffer jna = (PointShapeBuffer) Native.loadLibrary("FileGDBAPI", PointShapeBuffer.class);
}
}
并且出现以下错误:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'FileGDBAPI': The specified module could not be found.
我还尝试设置 VM 参数。任何建议都会很棒。
编辑:作为参考,我正在使用此处(需要注册)。
I'm using the following code to load a dll in JNA (irrelevant code is left out):
public class JNAMain {
public interface PointShapeBuffer extends Library { ... }
public static void main(String[] args){
System.setProperty("jna.library.path", "c:\\jnadll");
System.setProperty("java.library.path", "c:\\jnadll");
PointShapeBuffer jna = (PointShapeBuffer) Native.loadLibrary("FileGDBAPI", PointShapeBuffer.class);
}
}
And I get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'FileGDBAPI': The specified module could not be found.
I've also tried setting the VM args. Any suggestions would be great.
Edit: For reference, I am using a publicly available library found here (registration is required).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
根据我的经验,在 64 位 Win7 上从 64 位 jvm 调用 32 位本机 dll 时,您通常会看到此错误。 Win7 对于 64 位和 32 位应用程序的工作方式有所不同。
在64位Win7上,您可以调用本机32位dll中的函数,但您需要使用32位JVM。
原因是32位dll与64位应用程序不兼容,而64位Win7使用32位模拟器来运行32位应用程序。虽然Windows库可能被称为xxxx32.dll(例如user32.dll),但64位Win7上System32文件夹中的库是64位库,而不是32位,而SysWOW64中的库是32位库,令人困惑吧?!?
您还可以将该库放置在 32 位系统文件夹 (SysWOW64) 中,并从 32 位 JVM 中进行 JNI 调用。
查看以下链接以获取 64 位 Win7 如何处理库的完整说明;
http://www.samlogic.net/articles /32-64-bit-windows-folder-x86-syswow64.htm
如果您真的想帮助自己入睡,请尝试从这里开始;)
http://msdn.microsoft.com/en-us/windows/hardware /gg463051.aspx
In my experience you usally see this error when calling 32bit native dlls from a 64bit jvm on 64bit Win7. Win7 works differently for 64bit and 32bit applications.
On 64bit Win7 you can call functions in native 32bit dll's, but you need to use a 32bit JVM.
The reason for this is 32bit dll's are incompatible with 64bit applications, and 64bit Win7 uses a 32bit emulator to run 32bit applications. Although Windows Libraries might be called named xxxx32.dll (e.g. user32.dll) the libraries in the System32 folder on a 64bit Win7 are 64bit libraries, not 32bit, and the libraries in SysWOW64 are 32bit libraries, confusing right?!?
You can also place the library in the 32bit system folder (SysWOW64) and make the JNI call from within a 32bit JVM.
Check out the following link for a full explanantion as how 64bit Win7 handles libraries;
http://www.samlogic.net/articles/32-64-bit-windows-folder-x86-syswow64.htm
And if you really want to help yourself get to sleep, trying starting on this ;)
http://msdn.microsoft.com/en-us/windows/hardware/gg463051.aspx
将您的:更改
为:
如果您足够深入地研究 jna 源代码,您会在 NativeLibrary 类中找到一个不错的小钩子:
因此,如果您只是传递绝对路径并且甚至不使用 searchPath,它将捕获。这就是为什么您不必担心 jna.library.lib。
Change your:
to:
If you dive into the jna source code enough you will find a nice little hook in the NativeLibrary class:
So it will catch if you just passed an absolute path and not even use the searchPath. This was why you dont have to worry about jna.library.lib.
您需要指定包含 DLL 的文件夹,而不是 DLL 的实际路径。
例如,对于
c:\foo\bar\baz.dll
处的baz.dll
,路径应设置为c:\\foo\\bar
代码>. (请注意,在 Java 中,如果您使用退格键,则必须使用反斜杠对其进行转义)You need to specify the folder containing your DLL, not the DLL's actual path.
e.g. for
baz.dll
atc:\foo\bar\baz.dll
, the path should be set toc:\\foo\\bar
. (note in Java if you're using backspaces you'll have to escape them with backslashes)您可能需要下载包含 jna.jar 和 platform.jar 的最新版本并包含它们。那就不用设置路径了。
You might want to download the latest version with jna.jar and platform.jar and just include those. No need to set the path then.
就像在一些评论中已经提到的那样:检查 DLL/库的依赖关系。最好的工具是 Dependency Walker (http://www.dependencywalker.com/)。只有当你所有的依赖关系都满足时,jna 才能找到你的 DLL....我花了很长时间才弄清楚这一点
Like it was already mentioned in some comments: checks your Dependencies of your DLL/Library. Best Tool for this is Dependency Walker (http://www.dependencywalker.com/). Only if all your Dependencies are fulfilled, jna finds your DLL.... took me quite long to figure this out
这可能是因为合并到了 lebweb 套件中。我不确定,但那必须是只有现在你才能做一件事尝试这个。
尝试这个命令,如果你得到这个输出
或任何其他输出,那么你需要从系统中删除那个jna,因为如果程序本身有jna jar,那么就不需要系统jna。所以做这样的事情。
并尝试再次重新启动该应用程序。它将运行但未运行,然后尝试安装新版本的libwebkit-gtk。
希望这会有所帮助。这对我有帮助。
it is may be because there is the conflation into the lebweb kit. I am not sure but that has to be that only now u can do one thing try this.
try this command and if u getting this output
or any other output then this u need to remove then that jna from the system because if program itself have jna jar with that then there is no need of system jna for the same. so do something like this.
and try for restart that application again. it will run and it is not running then try to install new version of libwebkit-gtk.
hope this will help. this helped me.