JNA UnsatisfiedLinkError,但设置了jna.library.path [英] JNA UnsatisfiedLinkError, but jna.library.path is set

查看:550
本文介绍了JNA UnsatisfiedLinkError,但设置了jna.library.path的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在JNA中加载dll(忽略了不相关的代码):

    public class JNAMain {
       public interface PointShapeBuffer extends Library { ... }

       public static void main(String[] args){
          System.setProperty("jna.library.path", "c:\\jnadll");
          System.setProperty("java.library.path", "c:\\jnadll");

          PointShapeBuffer jna = (PointShapeBuffer) Native.loadLibrary("FileGDBAPI", PointShapeBuffer.class);
       }
    }

然后出现以下错误:

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

我也尝试设置VM参数.任何建议都会很棒.

供参考,我使用的是一个公共可用的库,此处(需要注册).

解决方案

以我的经验,当您在64位Win7上从64位jvm调用32位本机dll时,通常会看到此错误. Win7在64位和32位应用程序中的工作方式有所不同.

在64位Win7上,您可以在本地32位dll中调用函数,但是您需要使用32位JVM.

  1. 下载并安装32位Java运行时环境(JRE).您可以在同一台计算机上安装32位和64位的jvm,只需确保将它们安装在单独的目录中即可.
  2. 确保在执行程序时运行32位JRE而不是默认的64位JVM. A)将您的CLASSPATH和JAVA_HOME环境变量更改为指向32位jvm,或者编写脚本来设置CLASSPATH和JAVA_HOME并启动您的应用程序.

其原因是32位dll与64位应用程序不兼容,而64位Win7使用32位仿真器来运行32位应用程序.尽管Windows库可能被称为xxxx32.dll(例如user32.dll),但64位Win7上System32文件夹中的库是64位库,而不是32位,而SysWOW64中的库是32位库,令人困惑吧!! >

还可以将库放置在32位系统文件夹(SysWOW64)中,并从32位JVM中进行JNI调用.

请查看以下链接,了解有关64位Win7如何处理库的完整说明;

http://www.samlogic. net/articles/32-64-bit-windows-folder-x86-syswow64.htm

如果您真的想帮助自己入睡,请尝试从此开始;)

http://msdn.microsoft.com/en-us/Windows/硬件/gg463051.aspx

I'm using the following code to load a dll in JNA (irrelevant code is left out):

    public class JNAMain {
       public interface PointShapeBuffer extends Library { ... }

       public static void main(String[] args){
          System.setProperty("jna.library.path", "c:\\jnadll");
          System.setProperty("java.library.path", "c:\\jnadll");

          PointShapeBuffer jna = (PointShapeBuffer) Native.loadLibrary("FileGDBAPI", PointShapeBuffer.class);
       }
    }

And I get the following error:

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

I've also tried setting the VM args. Any suggestions would be great.

Edit: For reference, I am using a publicly available library found here (registration is required).

解决方案

In my experience you usally see this error when calling 32bit native dlls from a 64bit jvm on 64bit Win7. Win7 works differently for 64bit and 32bit applications.

On 64bit Win7 you can call functions in native 32bit dll's, but you need to use a 32bit JVM.

  1. Download and install 32bit Java Runtime Environment (JRE). You can install a 32bit and 64bit jvm on the same machine, just make sure they are installed in seperate directories.
  2. Ensure you run the 32bit JRE instead of the default 64bit JVM when you execute your program. Either A) change your CLASSPATH and JAVA_HOME environment variables to point to the 32bit jvm, or write a script to set the CLASSPATH and JAVA_HOME and launch you application.

The reason for this is 32bit dll's are incompatible with 64bit applications, and 64bit Win7 uses a 32bit emulator to run 32bit applications. Although Windows Libraries might be called named xxxx32.dll (e.g. user32.dll) the libraries in the System32 folder on a 64bit Win7 are 64bit libraries, not 32bit, and the libraries in SysWOW64 are 32bit libraries, confusing right?!?

You can also place the library in the 32bit system folder (SysWOW64) and make the JNI call from within a 32bit JVM.

Check out the following link for a full explanantion as how 64bit Win7 handles libraries;

http://www.samlogic.net/articles/32-64-bit-windows-folder-x86-syswow64.htm

And if you really want to help yourself get to sleep, trying starting on this ;)

http://msdn.microsoft.com/en-us/windows/hardware/gg463051.aspx

这篇关于JNA UnsatisfiedLinkError,但设置了jna.library.path的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆