How to generate a 64-bit .dll, which gcc compiler or another. Unable to load IA 32-bit.dll on AMD 64-bit platform

Hi, I did not find a solution how to create a 64 bit dll. And use its native C ++ methods. I am using metodynatywne.java java code:

class metodynatywne { static { System.loadLibrary("metodynatywne"); } native public void sayHello(); public static void main (String argv[]) { new metodynatywne().sayHello(); } } 

then the generated metodynatywne.h using javah -jni metodynatywne

I wrote the 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 used gcc to create my dll using the commands:

  c:\>c++ -I c:\java7\include -I c:\java7\include\win32 -c metodynatywne.cpp 

and

  c:\>c++ -shared metodynatywne.o -o metodynatywne.dll 

and that I get an 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 the Java 1.4 32-bit javac compiler and the java7 x64 compiler, both methods gave me the same error. How can I handle this? Use a different C ++ compiler, if so, how to get this compiler to create a usable java dll file. I am working on Windows 7 64 bit.

How can I make a 64-bit dll (with gcc) from a cpp file? Or another command command?

Thank you very much for any comments and help provided.

+6
source share
3 answers

You must recompile the DLL for 64-bit (you must download the 64-bit build tools). You can also switch to the 32-bit JVM (just load the 32-bit JVM).

0
source

This compiler flag should help: C ++ --64 -DARCH_X86_64 = 1 .cpp file

0
source

There is still no accepted answer to this question, so I will bite ... As Denis noted, you need to download the 64-bit compiler to create your .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 good installation package. Attention. If you are not using the installation package, you will need to install the entire tool chain yourself. Then you should use this 64-bit compiler executable (something like "x86_64-w64-mingw32-g ++") instead of the 32-bit gcc to generate your library.

As you noted above, you need to be careful about the version of java that you use to make sure that it matches the architecture of the C ++ library that you compiled. This means both the automatic Javah generation of your JNI header and the Java runtime from which you call it.

0
source

Source: https://habr.com/ru/post/944867/


All Articles