JNA java.lang.UnsatisfiedLinkError 和找不到指定的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16185200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 22:09:03  来源:igfitidea点击:

JNA java.lang.UnsatisfiedLinkError and The specified module could not be found

javajava-native-interfacenativejna

提问by user2306911

I'm putting together a jar that will let me call commands only available to natives (the jar uses natives rather then the actual program). Now I ran into a problem, whenever I load the DLL. Here is the error:

我正在整理一个 jar,它可以让我调用仅对本地人可用的命令(该 jar 使用本地人而不是实际程序)。现在我遇到了一个问题,每当我加载 DLL 时。这是错误:

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

at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:194)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:283)
at com.sun.jna.Library$Handler.<init>(Library.java:142)
at com.sun.jna.Native.loadLibrary(Native.java:368)
at com.sun.jna.Native.loadLibrary(Native.java:353)
at src.NativeBridgeJar.<clinit>(NativeBridgeJar.java:6)
at src.Main.main(Main.java:6)

I don't why what the cause of this error would be. I made sure I set the native library path to the folder with the native. Does anyone have an idea? Thanks in advanced!

我不知道为什么这个错误的原因是什么。我确保将本机库路径设置为带有本机的文件夹。有没有人有想法?先谢谢了!

回答by technomage

A) when you call Native.loadLibrary(), you may provide a shorthand name ("myDll"), a filename ("myDll.dll"), or the absolute path of the shared library ("c:/users/me/myDll.dll").

A) 当您调用 时Native.loadLibrary(),您可以提供速记名称(“myDll”)、文件名(“myDll.dll”)或共享库的绝对路径(“c:/users/me/myDll.dll”) .

B) If you don't provide an absolute path to the library, you may tell it where to load the DLL by specifying jna.library.path, or making it available on java.library.path(there are other options described in the NativeLibraryjavadoc).

B) 如果您没有提供库的绝对路径,您可以通过指定jna.library.path或使其可用来告诉它在哪里加载 DLL java.library.pathNativeLibraryjavadoc 中描述了其他选项)。

回答by Evgeniy Dorofeev

You should show JVM your dlls location. It can be done with -Djava.library.path=pathToDllVM argument

您应该向 JVM 显示您的 dll 位置。它可以用-Djava.library.path=pathToDllVM 参数来完成

回答by Fuzzy Analysis

I had the same problem until I put my .dll file into C:\Windows\System32 since it was a C++ DLL and had dependencies on Kernel32.dll and MSVCR100.dll in that folder. That seemed to work.

在我将 .dll 文件放入 C:\Windows\System32 之前,我遇到了同样的问题,因为它是一个 C++ DLL,并且依赖于该文件夹中的 Kernel32.dll 和 MSVCR100.dll。那似乎奏效了。

回答by nav3916872

In addition to setting the path of dll using -Djava.library.path=pathToDllor System.setProperty("jna.library.path","pathToDll");make sure the specific Visual C++ xxxx Redistributable Package is installed in your Windows(bcs the windows native libraries should have been built with specific VisualStudio xxxx)

除了使用设置 dll 的路径-Djava.library.path=pathToDllSystem.setProperty("jna.library.path","pathToDll");确保特定的 Visual C++ xxxx Redistributable Package 安装在您的 Windows 中(bcs Windows 本机库应该已使用特定的 VisualStudio xxxx 构建)