加载 dll 库文件时出现问题... java.lang.UnsatisfiedLinkError: Can't load library
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2407395/
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
Issue while loading a dll library file... java.lang.UnsatisfiedLinkError: Can't load library
提问by Bhaskara Krishna Mohan Potam
While loading a dll file, I am getting the following exception:
加载 dll 文件时,出现以下异常:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
D:\Transliteration\rlpnc-3.1.0-sdk-ia32-w32-msvc80\rlp\bin\ia32-w32-msvc80\btrntjni.dll:
The system cannot find message text for message number 0x%1 in the message file for %2
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.basistech.util.internal.Native.loadLibrary(Unknown Source)
at com.basistech.rnt.jni.<clinit>(Unknown Source)
at com.basistech.rnt.RNTEnvironment.<init>(Unknown Source)
at SampleTranslator.<init>(TranslateNameSample.java:88)
at TranslateNameSample.main(TranslateNameSample.java:62)
not sure about the root cause of the issue. Can anybody help me out in resolving this issue.
不确定问题的根本原因。任何人都可以帮我解决这个问题。
Thanks, Bhaskar
谢谢,巴斯卡
回答by Padmarag
Check that the "java.library.path" contains the folder containing .dll file.
On windows machine it is related to PATH.
http://www.inonit.com/cygwin/jni/helloWorld/load.html
检查“java.library.path”是否包含包含 .dll 文件的文件夹。
在 Windows 机器上,它与 PATH 相关。
http://www.inonit.com/cygwin/jni/helloWorld/load.html
回答by Dmitry Leskov
This does not have to do anything with the classpath. Place the DLL in the current directory, in one of the directories listed in the PATH environment variable, or, best of all, in the native library search path, set using the system property java.library.path:
这与类路径无关。将 DLL 放在当前目录中,在 PATH 环境变量中列出的目录之一中,或者最重要的是,在本机库搜索路径中,使用系统属性 java.library.path 设置:
java -Djava.library.path=C:\MyNativeLibs MyMainClass
回答by Stephen Kellett
As well as checking your are putting the path to the DLL in the correct environment variable you should also check the following:
除了检查您是否将 DLL 的路径放在正确的环境变量中,您还应该检查以下内容:
The DLL you are loading has all its dependencies satisfied. In other words, if this DLL depends on other DLLs, make sure those DLLs can also be found.
If the DLL being loaded uses a manifest to specify a specific DLL, ensure that DLL (of the version specified in the manifest) is also on the machine (or in the GAC, if required) and can be found
Check that all DLL functions referred in your Java code are correctly defined and exported and export the same datatypes as those your Java code is expecting. This won't stop the DLL loading, but it may well mess up the next stage - resolving link addresses or making functions that should work, fail in unexpected ways.
您正在加载的 DLL 已满足其所有依赖项。换句话说,如果此 DLL 依赖于其他 DLL,请确保也可以找到这些 DLL。
如果正在加载的 DLL 使用清单来指定特定的 DLL,请确保 DLL(清单中指定的版本)也在机器上(或在 GAC 中,如果需要)并且可以找到
检查 Java 代码中引用的所有 DLL 函数是否已正确定义和导出,并导出与 Java 代码期望的数据类型相同的数据类型。这不会停止 DLL 加载,但很可能会扰乱下一阶段 - 解析链接地址或制作应该工作的函数,但会以意想不到的方式失败。
Lots of fun to be had with this - lots of little things to trip you up. I had to deal with this a few years back messing with a text to speech package (in C & C++ in a DLL) working with different versions of Java with old and new JNI styles. What a mess!
这样做会带来很多乐趣 - 很多小事情会让你失望。几年前,我不得不处理这个问题,因为文本转语音包(在 C 和 C++ 中的 DLL 中)使用具有新旧 JNI 样式的不同版本的 Java。真是一团糟!
回答by fish
I have not seen this problem myself, but from the error message it sounds like some dependency needed by the DLL is either missing or incorrect version.
我自己还没有看到这个问题,但从错误消息来看,DLL 所需的某些依赖项要么丢失,要么版本不正确。
This tool might help: http://www.dependencywalker.com/
这个工具可能有帮助:http: //www.dependencywalker.com/
回答by dmurga
I work for the company that makes the product you're trying to use. We've seen this error when it's been installed against an incompatible version of the underlying layer we ship with it, because of missing dependent DLLs as others have suggested. Feel free to contact our support team for more help.
我为生产您尝试使用的产品的公司工作。当它安装在我们随附的不兼容版本的底层时,我们已经看到此错误,因为缺少其他人建议的依赖 DLL。如需更多帮助,请随时联系我们的支持团队。
回答by being_felicity
For me, adding the dll path to the VM options in my IDE worked.
对我来说,将 dll 路径添加到我的 IDE 中的 VM 选项是可行的。