JNA UnsatisfiedLinkError,但 jna.library.path 已设置

发布于 2024-11-26 16:26:53 字数 803 浏览 0 评论 0原文

我正在使用以下代码在 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 参数。任何建议都会很棒。

编辑:作为参考,我正在使用此处(需要注册)。

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

贩梦商人 2024-12-03 16:26:53

根据我的经验,在 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/hardware /gg463051.aspx

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

桃扇骨 2024-12-03 16:26:53

将您的:更改

Native.loadLibrary("FileGDBAPI", PointShapeBuffer.class);

为:

Native.loadLibrary("C:\\jnadll\\FileGDBAPI.dll", PointShapeBuffer.class);

如果您足够深入地研究 jna 源代码,您会在 NativeLibrary 类中找到一个不错的小钩子:

    /** Use standard library search paths to find the library. */
    private static String findLibraryPath(String libName, List searchPath) {
        //
        // If a full path to the library was specified, don't search for it
        //
        if (new File(libName).isAbsolute()) {
            return libName;
        }
        ...

因此,如果您只是传递绝对路径并且甚至不使用 searchPath,它将捕获。这就是为什么您不必担心 jna.library.lib。

Change your:

Native.loadLibrary("FileGDBAPI", PointShapeBuffer.class);

to:

Native.loadLibrary("C:\\jnadll\\FileGDBAPI.dll", PointShapeBuffer.class);

If you dive into the jna source code enough you will find a nice little hook in the NativeLibrary class:

    /** Use standard library search paths to find the library. */
    private static String findLibraryPath(String libName, List searchPath) {
        //
        // If a full path to the library was specified, don't search for it
        //
        if (new File(libName).isAbsolute()) {
            return libName;
        }
        ...

So it will catch if you just passed an absolute path and not even use the searchPath. This was why you dont have to worry about jna.library.lib.

各自安好 2024-12-03 16:26:53

您需要指定包含 DLL 的文件夹,而不是 DLL 的实际路径。

例如,对于 c:\foo\bar\baz.dll 处的 baz.dll,路径应设置为 c:\\foo\\bar代码>. (请注意,在 Java 中,如果您使用退格键,则必须使用反斜杠对其进行转义)

You need to specify the folder containing your DLL, not the DLL's actual path.

e.g. for baz.dll at c:\foo\bar\baz.dll, the path should be set to c:\\foo\\bar. (note in Java if you're using backspaces you'll have to escape them with backslashes)

离不开的别离 2024-12-03 16:26:53

您可能需要下载包含 jna.jar 和 platform.jar 的最新版本并包含它们。那就不用设置路径了。

You might want to download the latest version with jna.jar and platform.jar and just include those. No need to set the path then.

岁吢 2024-12-03 16:26:53

就像在一些评论中已经提到的那样:检查 DLL/库的依赖关系。最好的工具是 Dependency Walker (http://www.dependencywalker.com/)。只有当你所有的依赖关系都满足时,jna 才能找到你的 DLL....我花了很长时间才弄清楚这一点

Like it was already mentioned in some comments: checks your Dependencies of your DLL/Library. Best Tool for this is Dependency Walker (http://www.dependencywalker.com/). Only if all your Dependencies are fulfilled, jna finds your DLL.... took me quite long to figure this out

慕烟庭风 2024-12-03 16:26:53

这可能是因为合并到了 lebweb 套件中。我不确定,但那必须是只有现在你才能做一件事尝试这个。

$ dpkg -l | grep -i jna

尝试这个命令,如果你得到这个输出

ii  libjna-java  3.2.7-4 Dynamic access of native libraries from Java without JNI

或任何其他输出,那么你需要从系统中删除那个jna,因为如果程序本身有jna jar,那么就不需要系统jna。所以做这样的事情。

sudo apt-get autoremove libjna-java

并尝试再次重新启动该应用程序。它将运行但未运行,然后尝试安装新版本的libwebkit-gtk

希望这会有所帮助。这对我有帮助。

it is may be because there is the conflation into the lebweb kit. I am not sure but that has to be that only now u can do one thing try this.

$ dpkg -l | grep -i jna

try this command and if u getting this output

ii  libjna-java  3.2.7-4 Dynamic access of native libraries from Java without JNI

or any other output then this u need to remove then that jna from the system because if program itself have jna jar with that then there is no need of system jna for the same. so do something like this.

sudo apt-get autoremove libjna-java

and try for restart that application again. it will run and it is not running then try to install new version of libwebkit-gtk.

hope this will help. this helped me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文