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

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

问题描述

E:CodeJavaJNITest>java test
Exception in thread "main" java.lang.UnsatisfiedLinkError: E:CodeJavaJNITest	est.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)`

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

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?

推荐答案

您必须安装 32 位 JVM,然后才能运行您的代码.

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

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

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 本机接口 32 位 dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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