I am entering into Java world just now. I am facing problem when I try to compile sample program for Calling C from Java.
I wanted to try the sample code for JNI (W
The InOnIt page uses -mno-cygwin. If you want Cygwin functionality, then you'll want http://elliotth.blogspot.com/2005/08/porting-jni-code-to-win32-with-cygwin.html. Terminator's moved since that was written. The crux of the source you'd want for a Cygwin-safe Java launcher is now at https://github.com/software-jessies-org/jessies/blob/master/salma-hayek/native/all/java-launcher/java-launcher.cpp.
I couldn't get JNI
to work with Cygwin's g++
-- that induces a dependency on cygwin1.dll
, which clashes with the JNI mechanism
, causing a crash. The -mno-cygwin flag
is no longer supported. But using /bin/x86_64-w64-mingw32-g++.exe
fixed the problem for me.
Ensure that your native library is really loaded by adding a try/catch block around the System.loadLibrary()
call to catch the UnsatifiedLinkError Exception if your library could not be found.
If that doesn't work post your error, "it return aborted" isn't very helpful.
Also, you defined the native print method with a void return type, yet you have a return statement. Either remove that or let the method actually return something.