This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
loading DLLs created with Cygwin into Sun JDK
- From: "Marcus G. Daniels" <mgd at santafe dot edu>
- To: cygwin at cygwin dot com
- Date: Thu, 31 Jul 2003 22:09:40 -0600
- Subject: loading DLLs created with Cygwin into Sun JDK
I'm having a problem getting DLLs compiled with Cygwin to load into Sun
JDK 1.4.1. In the past this has worked, so I hope this is fixable
without too much work.
Here's an example. Take a simple Java Native Interface method like this:
$ cat jniTest.c
void Java_Test_test () { printf ("test\n");}
And compile it like so:
gcc -shared -o jniTest.dll jniTest.c
Also needed is the Java-side file:
public class Test {
public native void test ();
public static void main (String args[]) {
Test test = new Test ();
System.out.println ("loading jniTest");
System.loadLibrary ("jniTest");
System.out.println ("calling native method");
test.test ();
System.out.println ("success");
}
}
Compiled it like so from a Cygwin terminal (replace
/cygdrive/i/j2sdk1.4.1_02 as appropriate):
$ /cygdrive/i/j2sdk1.4.1_02/bin/javac Test.java
Now run it, you should see it print "loading jniTest", but nothing more.
$ CLASSPATH=. /cygdrive/i/j2sdk1.4.1_02/bin/java Test
In contrast, relink the DLL, but not using "-mno-cygwin":
$ gcc -mno-cygwin -shared -o jniTest.dll jniTest.c
$ CLASSPATH=. /cygdrive/i/j2sdk1.4.1_02/bin/java Test
Now it should print:
loading jniTest
calling native method
test
success
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/