bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.46k stars 581 forks source link

Can't load IA 32-bit .dll on a AMD 64-bit platform #663

Closed feng-for closed 1 year ago

feng-for commented 1 year ago

I use the example of the official website, execute the command java -jar javacpp.jar NativeLibrary.java -exec But what I expected didn't happen, Instead, the console outputs an error message. Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\.jdks\corretto-11.0.18\bin\jniNativeLibrary2.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method) at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2445) at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2501) at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2700) at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2651) at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:830) at java.base/java.lang.System.loadLibrary(System.java:1873) at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1825) at org.bytedeco.javacpp.Loader.load(Loader.java:1416) at org.bytedeco.javacpp.Loader.load(Loader.java:1227) at org.bytedeco.javacpp.Loader.load(Loader.java:1203) at NativeLibrary2$NativeClass.<clinit>(NativeLibrary2.java:8) at NativeLibrary2.main(NativeLibrary2.java:26) Caused by: java.lang.UnsatisfiedLinkError: C:\Users\Documents\test\learn\c\windows-x86_64\jniNativeLibrary2.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method) at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2445) at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2501) at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2700) at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2630) at java.base/java.lang.Runtime.load0(Runtime.java:768) at java.base/java.lang.System.load(System.java:1837) at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1772) ... 5 more How do I deal with it

saudet commented 1 year ago

It sounds like you're trying to use a 32-bit C++ compiler with a 64-bit JVM. You'll need to use a C++ compiler with the same number of bits as your JVM.

feng-for commented 1 year ago

What I know for sure is that the jdk is 64-bit. I suspect the following command is being executed java -jar javacpp.jar NativeLibrary.java -exec using a 32-bit C++ compiler. I don't know if I'm right about this

saudet commented 1 year ago

Yes, JavaCPP will just call cl.exe. If that's a 32-bit compiler, there's nothing JavaCPP can do about it. You'll need to give it a version of cl.exe that can compile in 64-bit.

feng-for commented 1 year ago

Yes, JavaCPP will just call cl.exe. If that's a 32-bit compiler, there's nothing JavaCPP can do about it. You'll need to give it a version of cl.exe that can compile in 64-bit.

I see, just reinstall the 64-bit cl.exe. Thanks! My cl.exe installed with Visual Studio Installer, I will use it to install 64-bit again. Thanks again!