Java JNI本机库加载64位和32位,但不加载';t在32位上运行
我的主计算机是Windows7 64位,我有一个JNI应用程序,但在我的笔记本电脑是WindowsXP32位,它无法工作。在笔记本电脑上,加载32位版本的本机DLL时不会出现Java JNI本机库加载64位和32位,但不加载';t在32位上运行,java,java-native-interface,mingw,32bit-64bit,unsatisfiedlinkerror,Java,Java Native Interface,Mingw,32bit 64bit,Unsatisfiedlinkerror,我的主计算机是Windows7 64位,我有一个JNI应用程序,但在我的笔记本电脑是WindowsXP32位,它无法工作。在笔记本电脑上,加载32位版本的本机DLL时不会出现未满足的linkerror,但在调用实际的本机方法时会出现错误。下面是我如何使用MinGW编译DLL的: cd bin javah MyClass move /Y MyClass.h ../ "%mingw64%\bin\g++" -shared -I"C:\Program Files\Java
未满足的linkerror
,但在调用实际的本机方法时会出现错误。下面是我如何使用MinGW编译DLL的:
cd bin
javah MyClass
move /Y MyClass.h ../
"%mingw64%\bin\g++" -shared -I"C:\Program Files\Java\jdk1.8.0_05\include" -I"C:\Program Files\Java\jdk1.8.0_05\include\win32" -o src/lib/MyLibrary.dll MyClass.cpp
@echo "Making the 32-bit library..."
g++ -shared -I"C:\Program Files\Java\jdk1.8.0_05\include" -I"C:\Program Files\Java\jdk1.8.0_05\include\win32" -o src/lib/MyLibrary_32.dll MyClass.cpp
下面是我用来加载库的代码,从技术上讲,它可以在两个处理器上工作
String processor = System.getProperty("sun.arch.data.model").equals("32") ? new String("_32") : new String("");
try { System.load(System.getProperty("user.dir") + "\\MyLibrary" + processor + ".dll"); }
catch(UnsatisfiedLinkError e) {
//If the dll was not found, extract the one packaged as a resource in the .jar
InputStream in = ML_Overworld.class.getClassLoader().getResourceAsStream("lib/MyLibrary" + processor + ".dll");
if(in == null) {
printError(String.format("MyLibrary%s.dll was not contained in the jar.", processor));
return;
}
File outPath = new File(System.getProperty("user.dir") + "\\MyLibrary" + processor + ".dll");
try {
DataOutputStream out = new DataOutputStream(new FileOutputStream(outPath));
try {
int input;
while((input = in.read()) != -1)
out.write(input);
out.close();
in.close();
}
catch(IOException e2) {
printError(String.format("MyLibrary%s.dll failed to extract: ", processor) + e2.getMessage() + ".");
return;
}
}
catch(FileNotFoundException e3) {
printError(String.format("MyLibrary%s.dll failed to extract: ", processor) + e3.getMessage() + ".");
return;
}
try { System.load(System.getProperty("user.dir") + "\\MyLibrary" + processor + ".dll"); }
catch(UnsatisfiedLinkError e4) {
printError(String.format("MyLibrary%s.dll failed to load: ", processor) + e4.getMessage() + ".");
return;
}
}
作为参考,以下是在32位笔记本电脑上抛出未满足链接错误的本机方法:
公共静态本机void readMap(字符串路径,cMap m)代码>
[解决方案]:在编译32位DLL时,在g++参数中添加了--kill at
。针对32位DLL运行。听起来好像少了什么东西。什么是g++与“%mingw64%\bin\g++”?你试过g++-m32吗?标准的MinGW只有32位。MinGW-64是另一个网站上的独立应用程序:。在我的64位上加载常规的g++编译DLL会产生一个不兼容错误。已修复,使用解决方案编辑主要帖子。的手册页