[英]Windows, JNA: Cannot load native library - UnsatisfiedLinkError
I am using Java 7 on Windows 7 and am trying to use Java JNA (Java Native Access) (4.2.2) [ link: https://github.com/java-native-access/jna ] to provide access to a C language native library . 我在Windows 7上使用Java 7 ,并尝试使用Java JNA (Java本机访问)(4.2.2)[链接: https : //github.com/java-native-access/jna ]提供对C语言的访问语言本机库 。 I have done this on a Linux system and have no problems finding and loading the library.
我已经在Linux系统上完成了此任务,并且找到并加载库没有问题。
I am using the suggested technique of setting the system property jna.library.path to the path where the library is located. 我正在使用将系统属性jna.library.path设置为库所在路径的建议技术。 As mentioned above, this works on Linux, but on Windows I cannot get it to find and load the library.
如上所述,这在Linux上有效,但是在Windows上我无法找到并加载该库。
On the Windows platform, the library comes in both 32 and 64 bit variants (I'm trying to use the 32-bit), with both .lib and .dll files. 在Windows平台上,该库具有32位和64位变体(我正在尝试使用32位),同时具有.lib和.dll文件。
I also set the system properties jna.debug_load and jna.debug_load.jna to true as suggested to watch how JNA does its thing. 我还按照建议将系统属性jna.debug_load和jna.debug_load.jna设置为true ,以观察JNA的工作方式。
I have tried the following to no avail: 我尝试了以下无济于事:
When I make an attempt, I can see the debug information on the Java console. 尝试时,可以在Java控制台上看到调试信息。 Oddly, it tries the exact path to where the library file sits - and yet does not find it .
奇怪的是,它尝试查找库文件所在的确切路径,但找不到它 。
If anyone has run into this and knows anything about solving the problem, it would be much appreciated. 如果有人遇到了这个问题并且对解决问题一无所知,将不胜感激。
Trying (via loadLibrary) jnidispatch
Looking in classpath from sun.misc.Launcher$AppClassLoader@1a1a7aa4 for /com/sun/jna/win32-x86-64/jnidispatch.dll
Found library resource at jar:file:/C:/Users/jo24447/.m2/repository/net/java/dev/jna/jna/4.2.2/jna-4.2.2.jar!/com/sun/jna/win32-x86-64/jnidispatch.dll
Trying C:\Users\jo24447\AppData\Local\Temp\jna--734724592\jna8544680981267090708.dll
Found jnidispatch at C:\Users\jo24447\AppData\Local\Temp\jna--734724592\jna8544680981267090708.dll
Looking for library 'VixAllProductsDyn'
Adding paths from jna.library.path: C:\Program Files (x86)\VMware\VMware VIX
Trying C:\Program Files (x86)\VMware\VMware VIX\VixAllProductsDyn.dll
Adding system paths: []
Trying C:\Program Files (x86)\VMware\VMware VIX\VixAllProductsDyn.dll
Looking for lib- prefix
Trying libVixAllProductsDyn.dll
Looking in classpath from sun.misc.Launcher$AppClassLoader@1a1a7aa4 for VixAllProductsDyn
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'VixAllProductsDyn': Native library (win32-x86-64/VixAllProductsDyn.dll) not found in resource path ([file:/C:/Users/jo24447/luna_workspace/VMUtil/vm-util/target/classes/, file:/C:/Users/jo24447/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar, file:/C:/Users/jo24447/.m2/repository/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.jar, file:/C:/Users/jo24447/.m2/repository/org/slf4j/slf4j-log4j12/1.7.2/slf4j-log4j12-1.7.2.jar, file:/C:/Users/jo24447/.m2/repository/net/java/dev/jna/jna/4.2.2/jna-4.2.2.jar, file:/C:/Users/jo24447/.m2/repository/net/java/dev/jna/jna-platform/4.2.2/jna-platform-4.2.2.jar])
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:277)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:403)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:342)
at edu.mit.ll.oms.security.vm.VIXLibrary.<clinit>(VIXLibrary.java:24)
at edu.mit.ll.oms.security.vm.test.QuickTest.main(QuickTest.java:16)
(1) Try the following: (1)尝试以下方法:
(2) Secondly did you try to set the path like this: java -Djava.library.path=c:\\yourLocation VixAllProductsDyn (2)其次,您是否尝试像这样设置路径:java -Djava.library.path = c:\\ yourLocation VixAllProductsDyn
(3) If you have an applet/webstart application you can specify the native library location with the native lib attribute. (3)如果您有applet / webstart应用程序,则可以使用native lib属性指定本地库位置。
(4) Other than that you may answer the following questions: What architecture (32/64Bit) does your windows system have? (4)除此之外,您可能会回答以下问题:Windows系统具有什么体系结构(32 / 64Bit)? What architecture (32/64Bit) does your java have?
您的Java有什么架构(32 / 64Bit)? What version of the dll do you try to run in which case?
在这种情况下,您尝试运行哪个版本的dll?
Maybe you try an invalid combination of system architecture / JVM and library version... 也许您尝试使用无效的系统架构/ JVM和库版本组合...
Update: 更新:
Can you share your code? 您可以共享您的代码吗? It should look something like this:
它看起来应该像这样:
VixAllProductsDyn lib = (VixAllProductsDyn) Native.loadLibrary("VixAllProductsDyn", VixAllProductsDyn.class);
The VixAllProductsDyn.java is an interface containing all methods you want to use: VixAllProductsDyn.java是包含您要使用的所有方法的接口:
public interface VixAllProductsDyn extends Library {
public abstract NativeLong OneOfTheMethodsYouWantToCall();
...
}
Are you sure that you included all the necessary *.dlls and *.libs etc. which are needed? 您确定已包含所有必需的* .dll和* .libs等吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.