Vilib
Vilib

Reputation: 93

Java JNI - Can't load IA 32-bit .dll on a AMD 64-bit platform

I tried create a JNI helloworld project using this tutorial. I completed every step on the page. Unfortunately after trying to call the programm with java -Djava.library.path="C:/Users/Philipp/Desktop/jni" HelloWorld i get the following error message:

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\Philipp\Desktop\jni\helloworld.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 HelloWorld.<clinit>(HelloWorld.java:3)

There are a few questions on stackoverflow with this type of error, unfortunately none of the solutions are working for me.

I want to stay on JDK 64 bit, so I guess I have to compile my C-code for a 64-bit machine. I tried using the -m64 keyword: gcc -shared HelloWorld.c -I"C:/Program Files/Java/jdk1.8.0_121/include" -I"C:/Program Files/Java/jdk1.8.0_121/include/win32" -o libhelloworld.dll -m64 which leads to the following error:

HelloWorld.c:1:0: sorry, unimplemented: 64-bit mode not compiled in
 #include <jni.h>
 ^

What do I have to do to get it running?

Upvotes: 0

Views: 1513

Answers (1)

user7859067
user7859067

Reputation:

You need a x86_64 GCC toolchain to compile it for x64(if you are in windows, probably mingw). And you are right, as your JDK is AMD64, so the SO/DLL need to be AMD64 too.

In windows you either install x86_64-w64-mingw32- toolchain by cygwin env or msys2, or go for Microsoft C compiler.

Upvotes: 1

Related Questions