java - JNI %1 is not a valid Win32 application -
i'm running netbeans on 64-bit windows 8, jdk 1.7_25 (64-bit), following instructions beginning jni netbeans (https://netbeans.org/kb/docs/cnd/beginning-jni-linux.html)
the instructions linux, principle same windows believe (generating .dll file instead of .so, using win32 includes in jdk, etc)
i have cygwin64 installed cygwin32. using cygwin64, i'm able generate 64-bit dll c/c++ dynamic library project. however, when call system.load("path/to/jnitest.dll"), get:
exception in thread "main" java.lang.unsatisfiedlinkerror: c:\users\andrew\documents\netbeansprojects\jnitestlib\dist\jnitest.dll: %1 not valid win32 application @ java.lang.classloader$nativelibrary.load(native method) @ java.lang.classloader.loadlibrary1(classloader.java:1957) @ java.lang.classloader.loadlibrary0(classloader.java:1882) @ java.lang.classloader.loadlibrary(classloader.java:1843) @ java.lang.runtime.load0(runtime.java:795) @ java.lang.system.load(system.java:1061) @ jnitest.jnitest.main(jnitest.java:8) java result: 1
from gather, case when loading 64-bit application on 32-bit virtual machine, netbeans.conf pointing 64-bit jvm.
additionally, when use 32-bit version of cygwin compile things , run, get
can't load ia 32-bit .dll on amd 64-bit platform
i'm pretty sure i'm correctly generating dll file, it's simple helloworld printf follow jni tutorial. i'm new jni , c, i'm not sure start debugging. best i've done tried both 32 , 64-bit dlls, , i've made sure c compiler (cygwin) 64-bit, , jvm too.
i'd appreciate insight!
edit: here included files
=== java (jnitest.java) ===
package jnitest; public class jnitest { public static void main(string[] args) { system.out.println("jvm: " + system.getproperty("sun.arch.data.model")); system.load("c:\\users\\andrew\\documents\\netbeansprojects\\jnitestlib\\dist\\jnitest.dll"); new jnitest().dohello(); } public native void dohello(); }
=== generated javah header (jnitest_jnitest.h) ===
/* not edit file - machine generated */ #include <jni.h> /* header class jnitest_jnitest */ #ifndef _included_jnitest_jnitest #define _included_jnitest_jnitest #ifdef __cplusplus extern "c" { #endif /* * class: jnitest_jnitest * method: dohello * signature: ()v */ jniexport void jnicall java_jnitest_jnitest_dohello (jnienv *, jobject); #ifdef __cplusplus } #endif #endif
=== c (jnitest.c) ===
#include <jni.h> #include "jnitest_jnitest.h" jniexport void jnicall java_jnidemojava_main_nativeprint (jnienv *env, jobject obj) { printf("\nhello world c\n"); }
edit:
the problem seems dll, since can load other 64-bit dlls fine. thought cygwin might problem, changed compiler mingw-w64. compiled fine, , library loads, new exception:
exception in thread "main" java.lang.unsatisfiedlinkerror: jnitest.jnitest.dohello()v @ jnitest.jnitest.dohello(native method) @ jnitest.jnitest.main(jnitest.java:10) java result: 1
some more digging found error thrown when classloader reads libs.size() here:
// invoked in vm class linking code. static long findnative(classloader loader, string name) { vector<nativelibrary> libs = loader != null ? loader.nativelibraries : systemnativelibraries; synchronized (libs) { int size = libs.size(); (int = 0; < size; i++) { nativelibrary lib = libs.elementat(i); long entry = lib.find(name); if (entry != 0) return entry; } } return 0; }
edit: answers!
finally figured out.
firstly, wrong cygwin64. using different 64-bit c compiler got rid of not valid win32 application error.
secondly, jnitest.c file's method signature incorrect. should have been:
java_jnitest_jnitest_dohello
instead of
java_jnitest_main_dohello
after changing that, works!
(though can't answer own question 6 hours... dum de dum)
finally figured out.
firstly, wrong cygwin64. using different 64-bit c compiler got rid of not valid win32 application error.
secondly, jnitest.c file's method signature incorrect. should have been:
java_jnitest_jnitest_dohello
instead of
java_jnitest_main_dohello
after changing that, works!
Comments
Post a Comment