I have compiled a test dll for use with jni. It is actually completely empty except for #include<jni.h>. It compiles fine. I commented out everything else to try and get it working. I used gcc cygwin version and -shared and eclipse.
This is the class that loads the library:
static
{
final File f= new File(new File("res"), "mandc.dll");
System.out.println(f.exists());
System.load(f.getAbsolutePath());
System.out.println("Loaded!");
}
// public static native long mand(final double cx, final double cy,
// final double jx, final double jy, long iter);
public static native void mand();
true is the last thing that prints, proving that the error is between true and loaded!.
If I run from within eclipse, two error messages print, but the internet does not know what they are.
the messages:
2 [main] javaw <random number here> exception::handle: Exception: STATUS_STACK_OVERFLOW
667 [main] javaw <random number here> open_stackdumpfile: Dumping stack trace to javaw.exe.stackdump
the stack dump is uninformative.
Exception: STATUS_STACK_OVERFLOW at eip=61157C62
eax=0001C038 ebx=49E0834C ecx=49DE2ABC edx=49E27DB4 esi=49E07B2C edi=49E27B34
ebp=49E07ACC esp=49E07AB4 program=C:\Program Files\Java\jre7\bin\javaw.exe, pid 2688, thread main
cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
Stack trace:
Frame Function Args
49E07ACC 61157C62 (49E2D000, 49E27B3A, 49E27DB4, 00000008)
49E07AFC 6106C0B5 (49E27B3A, 49E27D78, 00000008, 49E27B2C)
49E27B4C 6106C6D1 (49E27B70, 00000C90, 00000000, 49E27DB4)
49E27DEC 6100584E (49E27EBC, 611FBAF0, 611FBAEC, 49E27E2C)
49E27E3C 61005D28 (49E27FC3, 611FBAF0, 611FBAEC, 00000001)
49E2801C 61006F07 (00000000, 49E28058, 61006990, 49E2B268)
End of stack trace
The experiment also fails when I run the example from the wikipedia page. And it fails the same way.
Problem fixed. I switched toolchains from the cygwin gcc to the mingw gcc. To support this, I had to install extra mingw packages from the cygwin install program.
I guess that cygwin is incompatible with java. A better error message would have been appreciated.