尝试使用Java(JNA)中的DLL。无法加载库异常 [英] Trying to use DLL from Java (JNA). Unable to load library exception
问题描述
线程main中的异常 java.lang.UnsatisfiedLinkError:无法加载库
'simpleDLL' :找不到指定的模块。
试图将simpleDLL.dll放在项目库中,在system32文件夹中复制文件没有成功。
我在加载DLL时有完全相同的问题,我以这种方式解决了:
- 正如Christian Kuetbach所说,检查您使用的simpleDLL是否与处理器的体系结构兼容,32位DLL不能在64位机器上工作,还有64位DLL不能在32位机器上工作。
-
如果DLL兼容,则问题可能在您的java库路径中。我将我的DLL放入
user.dir
目录中,然后我使用这个代码:
将Java库路径设置为
user.dir
或者您想要的其他路径:String myLibraryPath = System.getProperty(user.dir); //或另一个绝对或相对路径
System.setProperty(java.library.path,myLibraryPath);
加载库:
系统。 loadLibrary(libraryWithoutDLLExtension);
它为我工作,尝试它告诉我,如果它适用于你。
I have NetBeans project from tutorial which causes exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library
'simpleDLL': The specified module could not be found.
Tried to put simpleDLL.dll in project libraries, copied file in system32 folder with no success.
I had exactly the same problem with loading a DLL, I solved it in this way:
- 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.
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: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);
Load the library:
System.loadLibrary("libraryWithoutDLLExtension");
It worked for me, try it and tell me if it works for you.
这篇关于尝试使用Java(JNA)中的DLL。无法加载库异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!