尝试使用来自 Java (JNA) 的 DLL.无法加载库异常 [英] Trying to use DLL from Java (JNA). Unable to load library exception

查看:38
本文介绍了尝试使用来自 Java (JNA) 的 DLL.无法加载库异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自 教程 的 NetBeans 项目,其中导致异常:

I have NetBeans project from tutorial which causes exception:

线程main"中的异常java.lang.UnsatisfiedLinkError:无法加载库 'simpleDLL':找不到指定的模块.

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'simpleDLL': The specified module could not be found.

尝试将simpleDLL.dll放入工程库中,复制system32文件夹中的文件没有成功.

Tried to put simpleDLL.dll in project libraries, copied file in system32 folder with no success.

推荐答案

我在加载 DLL 时遇到了完全相同的问题,我是这样解决的:

I had exactly the same problem with loading a DLL, I solved it in this way:

  • 正如 Christian Kuetbach 所说,检查您使用的 simpleDLL 是否与您的处理器架构兼容,32 位 DLL 在 64 位机器上不起作用,64 位 DLL 也不会'在 32 位机器上工作.

  • As Christian Kuetbach said, check if the simpleDLL you are using is compatible with your processor's architecture, a 32-bit DLL won't work on a 64-bit machine, and also a 64-bit DLL won't work on a 32-bit machine.

如果 DLL 兼容,则问题可能出在您的 java 库路径中.我将我的 DLL 放入 user.dir 目录,然后我使用了以下代码:

If the DLL is compatible, then the problem may be in your java library path. I put my DLL into the user.dir directory and then I used this code:

将 Java 库路径设置为 user.dir 或者您想要的其他路径:

Set Java library path to user.dir or maybe another path you want:

 String myLibraryPath = System.getProperty("user.dir");//or another absolute or relative path

 System.setProperty("java.library.path", myLibraryPath);

加载库:

 System.loadLibrary("libraryWithoutDLLExtension");

它对我有用,试试吧,然后告诉我它是否适合你.

It worked for me, try it and tell me if it works for you.

这篇关于尝试使用来自 Java (JNA) 的 DLL.无法加载库异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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