64位系统上的Java Native Interface 32位dll [英] Java Native Interface 32 bit dll on 64 bit system

查看:236
本文介绍了64位系统上的Java Native Interface 32位dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

线程main中的异常java.lang.UnsatisfiedLinkError:E:\Code\Java

\JNITest\test.dll:无法加载IA 32位.dll在AMD 64位平台上
在java.lang.ClassLoader $ NativeLibrary.load(Native Method)
在java .lang.ClassLoader.loadLibrary0(未知源)
在java.lang.ClassLoader.loadLibrary(未知源)
在java.lang.Runtime.loadLibrary0(未知源)
在java.lang .System.loadLibrary(Unknown Source)
at test.main(test.java:16)`

在使用Java Native Interface时遇到一个产生此错误的问题。我相信这是因为我编译的.dll与MinGW编译为32位.dll,而我的系统是64位,因此我的Java运行在64位。
有没有强制我的Java以32位运行?

解决方案

你必须安装32位JVM,您将能够运行代码。



如果要分发应用程序,您将需要构建32位和64位版本的DLL。然后使用以下技术使正确的DLL加载,无论您的客户拱。将32或64(MyJniDLL32.dll和MyJniDLL64.dll)附加到您生成的输出文件。

  String archDataModel = System.getProperty( sun.arch.data.model); 
System.loadLibrary(libraryName + archDataModel);


E:\Code\Java\JNITest>java test
Exception in thread "main" java.lang.UnsatisfiedLinkError: E:\Code\Java\JNITest\test.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
    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.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at test.main(test.java:16)`

While using Java Native Interface I ran into a problem that generated this error. I believe this is because I compiled the .dll with MinGW which compiles to a 32-bit .dll whilst my system is 64-bit and thus my Java runs at 64-bit. Is there anyway to force my Java to run at 32-bits?

解决方案

You'll have to install a 32bit JVM and you will be able to run your code.

If you are going to distribute your application, you will want to build both 32bit and 64bit versions of your DLL. Then use the following technique to have the proper DLL loaded regardless of your customers arch. Append either a 32 or a 64 (MyJniDLL32.dll & MyJniDLL64.dll) to your generated output file.

    String archDataModel = System.getProperty("sun.arch.data.model");
    System.loadLibrary(libraryName+archDataModel);

这篇关于64位系统上的Java Native Interface 32位dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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