From: khan AT xraylith DOT wisc DOT edu (Mumit Khan) Subject: [ANN] Java JNI examples for Cygwin/Mingw 21 Jan 1999 22:29:04 -0800 Message-ID: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII To: gnu-win32 AT cygnus DOT com See ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/misc/ for examples on shows how to create Java JNI's with either Cygwin GCC or Mingw GCC. Please send bug reports directly to me (but please do make sure it's not a bug in your code, so do run it with other compilers first if at all possible). Here's an abridged version of the README file: Writing JNI using GCC on win32: =========================================================================== I've provided two simple examples, one in C and other in C++ (this also tests global constructors and destructors). Requirements: - JDK of course. - cygwin B20.1 or newer : You of course only need this if you need to use Cygwin. For Mingw, ie., native win32, you already have the required runtime. See my gnu-win32 page below for a short discussion of what is cygwin/mingw/etc. - GNU EGCS-1.1.1 development tools If you have stock Cygwin b20.1, you have EGCS-1.1, which should work as well. Changes to JDK headers needed for GCC: ====================================== GCC doesn't have a __int64 built-in, and this patch basically uses "long long" instead. 1. Edit the file /include/win32/jni_md.h, Where is the installation root (eg., c:/jdk1.1.7A). 2. Replace the segment: typedef long jint; typedef __int64 jlong; with: typedef long jint; #ifdef __GNUC__ typedef long long jlong; #else typedef __int64 jlong; #endif typedef signed char jbyte; and that's it. Or, you can use patch on the jdk-1.1.patch file included which automates this. Examples: ========= * c/HelloWorld: Thanks to Andrew Mickish * c++/HelloWorld: A C++ version. For Cygwin, just cd to the "c" and "c++ directories, and type `make' to build the DLLs. For Mingw, use makeit.bat files in these directories. Mingw32 notes: ============== Since Java as distributed by Sun requires MSVC 4.2, it probably depends on some of the MSVC's features, either of the runtime or of the compiler; for this reason alone, mingw will probably be the most stable platform for developing JNI's when using GCC. Cygwin32 notes: ============== Since Java as distributed by Sun requires MSVC 4.2, it probably depends on some of the MSVC's features, either of the runtime or of the compiler; for this reason alone, cygwin will probably *NOT* be the most stable platform for developing JNI's when using GCC. Oh, the joys of cut and paste ;-) The good news is that Cygwin B20.1 supports Java JNI's quite well, and I've run a large 3D PDE solver that MSVC can't even compile (uses C++ expression templates and so on). Creating Java JNI with Cygwin tools is just as easy as creating these with MSVC or some other commercial native tools, except for one small, but important, difference: since Java is not a "Cygwin native" application, we need to initialize the Cygwin DLL differently and for that we supply an alternative entry point when building the DLL. The new entry point, __cygwin_noncygwin_dll_entry AT 12, was introduced in B20.1 as an interim measure; starting from B21, we should not need to do this anymore. THANKS: ======= Many thanks to Andrew Mickish and Glenn Fullmer for all their help. Regards, Mumit - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".