java - 无法从 netbeans 使用 jna 加载个人 dll

标签 java dll jna

我使用的是 netbeans 7.4/jdk 1.7u51

我从官方网站下载了 JNA 的 jar,版本为 4.0.0。

我有一个内部开发的 DLL,其接口(interface)采用纯 C 语言,可以很好地与 python 中的 ctypes 加载。该dll是在Visual 2010版本中编译的,其运行时位于路径中。

D:\fl006\Downloads>dir D:\deploy\SpotLight\spotlight-1488\PasanBusLibrary.dll
 Directory of D:\deploy\SpotLight\spotlight-1488

29.01.2014  11:13         1'690'112 PasanBusLibrary.dll

我尝试使用 jna 在 java 中加载它:

public interface CLibrary extends Library {
     (...snip...)
    void pasanIpcInitializeLibrary(String xClient, String xBusName, int xTimeout);
    void pasanIpcTerminateLibrary();
}

public static void main(String[] args) {
    NativeLibrary.addSearchPath("PasanBusLibrary","D:\\deploy\\SpotLight\\spotlight-1488");
    CLibrary Bus = (CLibrary) Native.loadLibrary("PasanBusLibrary",CLibrary.class);
(... snip ...)    

这基本上是从自定义位置加载的书外标准 dll。

激活 jna debug 时,我看到以下内容:

run:
Looking in classpath from sun.misc.Launcher$AppClassLoader@714a8f44 for /com/sun/jna/win32-x86-64/jnidispatch.dll
Found library resource at jar:file:/D:/code/perso/TestWrapperBus/jna-4.0.0.jar!/com/sun/jna/win32-x86-64/jnidispatch.dll
Looking for library 'PasanBusLibrary'
Adding paths from jna.library.path: null
Trying D:\deploy\SpotLight\spotlight-1488\PasanBusLibrary.dll
Adding system paths: []
Trying D:\deploy\SpotLight\spotlight-1488\PasanBusLibrary.dll
Looking for lib- prefix
Trying libPasanBusLibrary.dll
Looking in classpath from sun.misc.Launcher$AppClassLoader@714a8f44 for PasanBusLibrary
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'PasanBusLibrary': Native library (win32-x86-64/PasanBusLibrary.dll) not found in resource path ([file:/D:/code/perso/TestWrapperBus/jna-4.0.0.jar, file:/D:/code/perso/TestWrapperBus/jna-platform-4.0.0.jar, file:/D:/code/perso/TestWrapperBus/build/classes/])
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:271)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
    at com.sun.jna.Library$Handler.<init>(Library.java:147)
    at com.sun.jna.Native.loadLibrary(Native.java:412)
    at com.sun.jna.Native.loadLibrary(Native.java:391)
    at testwrapperbus.TestWrapperBus.main(TestWrapperBus.java:39)

看起来它查看了我给出的位置并以某种方式丢弃了它。我尝试了不同的文件夹,得到了相同的行为,没有明显的文件系统正确问题(dll 是所有用户的 RW)

关于我缺少什么的任何线索,我目前有点陷入困境......

编辑

  • 如果我加载“msvcrt”,这对于 cll printf 来说效果很好
  • 我的 dll 有一些依赖项,它们全部托管在 c:\windows\system32 中(标准运行时,动态链接)

最佳答案

我的dll是win32编译的,而我使用的是win64 JDK/JRE。当然,在处理纯java时,我们不在乎,但加载本地库需要匹配。

我尝试在 32 位 JRE7 上从命令行运行并且它有效,因此我非常确定在我的 netbeans 中安装适用于 win32 的 JDK 或以 64 位重新编译我的 dll 将解决该问题。

感谢这个答案:Trying to use DLL from Java (JNA). Unable to load library exception让我走上正路

关于java - 无法从 netbeans 使用 jna 加载个人 dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21486086/

相关文章:

java - Path.equals() 在 Windows 10 上为两个不同的文件夹(小写 m 和大写 M)返回 true

java - 单击链接时希望在 jsp 页面中多一个选项

java - java中如何修剪运行时变量的空格?

haskell - Haskell 和 Awesomium 的运行时 DLL 问题

java - 线程 "main"java.lang.UnsatisfiedLinkError : undefined symbol: Test 中的异常

java - 无法在 Derby 数据库中找到表

delphi - Delphi-使用现有dll的问题

windows - LoadLibraryEx 忽略完全限定路径名?

java - JavaCL 和 JogAmp JOCL 比较如何?

java - 无法在java中实例化结构内部的结构