1Codeforces's blog

By 1Codeforces, 12 years ago, In English

Hi I didn't find solution how to create 64 bit dll. And use it's native c++ methods. I use Java code 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

I wrote metodynatywne.cpp code :


#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 :

 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. How can I deal with that? Use another c++ compiler if yes how force this compiler to create usable by my java dll file. I working on Windows 7 64 bit.

How I can make from cpp file a 64 bit dll (with gcc) ? Or other comand line compiler ?

Thanks in advance for help.

  • Vote: I like it
  • +10
  • Vote: I do not like it

| Write comment?