[英]How to generate 64 bit .dll which gcc compiler or other. Can't load IA 32-bit .dll on a AMD 64-bit platform
Hi I didn't find solution how to create 64 bit dll. 嗨,我没有找到解决方案如何创建64位DLL。 And use it's native c++ methods.
并使用它的原生c ++方法。 I use Java code metodynatywne.java :
我使用Java代码metodynatywne.java:
class metodynatywne {
static {
System.loadLibrary("metodynatywne");
}
native public void sayHello();
public static void main (String argv[])
{
new metodynatywne().sayHello();
} }
then generated metodynatywne.h using javah -jni metodynatywne 然后使用javah -jni metodynatywne生成metodynatywne.h
I wrote metodynatywne.cpp code : 我写了metodynatywne.cpp代码:
#include <jni.h>
#include <iostream>
#include "metodynatywne.h"
using namespace std;
JNIEXPORT void JNICALL
Java_metodynatywne_sayHello(JNIEnv * env, jobject self)
{
cout << "Hello World!" << endl;
}
I ussed gcc to create my dll with comands : 我用gcc用命令创建了我的dll:
c:\>c++ -I c:\java7\include -I c:\java7\include\win32 -c metodynatywne.cpp
and 和
c:\>c++ -shared metodynatywne.o -o metodynatywne.dll
and what what I'm getting is error message: 我得到的是错误信息:
c:\>java metodynatywne
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Programowanie\UJ\Semestr2\ZPG\PerfCount\cwiczenie\metodynatywne.dll: Can't lo
ad IA 32-bit .dll on a AMD 64-bit platform
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(Unknown Source)
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 metodynatywne.<clinit>(metodynatywne.java:4)
I used Java 1.4 32 bit javac compiler and java7 x64 compiler both metods gave me the same error. 我使用Java 1.4 32位javac编译器和java7 x64编译器两个metods给了我同样的错误。 How can I deal with that?
我该怎么处理? Use another c++ compiler if yes how force this compiler to create usable by my java dll file.
如果是,请使用另一个c ++编译器如何强制此编译器创建可用于我的java dll文件。 I working on Windows 7 64 bit.
我在Windows 7 64位上工作。
How I can make from cpp file a 64 bit dll (with gcc) ? 我如何从cpp文件制作64位dll(使用gcc)? Or other comand line compiler ?
还是其他命令行编译器?
Thanks a lot for any comments and help provided. 非常感谢您提供的任何评论和帮助。
You should recompile the DLL for 64-bit (you must download 64-bit build tools). 您应该重新编译64位的DLL(您必须下载64位构建工具)。 Also you can switch to 32-bit JVM (just download 32-bit JVM).
您也可以切换到32位JVM(只需下载32位JVM)。
这个编译器标志应该有帮助:c ++ --64 -DARCH_X86_64 = 1 file.cpp
Still no accepted answer on this one, so I'll bite... As Denis mentioned, you'll need to download a 64-bit compiler for generating your .dll. 仍然没有接受这个问题的答案,所以我会咬人......正如Denis所说,你需要下载一个64位编译器来生成你的.dll。 These days most people use MinGW-w64 for this on Windows ( http://www.mingw.org or direct download here http://sourceforge.net/projects/mingw-w64/files/latest/download?source=files ) which has a pretty nice installation package.
这些天大多数人在Windows上使用MinGW-w64( http://www.mingw.org或直接下载http://sourceforge.net/projects/mingw-w64/files/latest/download?source=files )它有一个非常好的安装包。 Caution - If you don't use the installation package you'll need to install the whole toolchain on your own.
注意 - 如果您不使用安装包,则需要自己安装整个工具链。 Then you would use this 64-bit compiler executable (something like 'x86_64-w64-mingw32-g++') instead of the 32-bit gcc to generate your library.
然后你将使用这个64位编译器可执行文件(类似'x86_64-w64-mingw32-g ++')而不是32位gcc来生成你的库。
As you noted above, you do need to be careful about the version of java you are using to be sure it matches the architecture of the C++ library you have compiled. 如上所述,您需要注意所使用的java版本,以确保它与您编译的C ++库的体系结构相匹配。 This means both the Javah auto-generation of your JNI header and the Java runtime that you call it from.
这意味着您的JNI标头的Javah自动生成和您从中调用它的Java运行时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.