Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JNI + cygwin broken?

Reply
Thread Tools

JNI + cygwin broken?

 
 
wenchao Tao
Guest
Posts: n/a
 
      05-09-2004
Greetings,

I need to use JNI to interface to an old big C++ library from Java.
And everything seems to be working on the test machine with
j2sdk1.4.2_02-b03, cygwin 1.5.5, and Windows XP. However as I moved
the application to another machine with the newest j2sdk
(j2sdk1.4.2_04-b32c) and cygwin (1.5.9), the JNI failed to work. With
help of a simple test program, I have found that the jvm failed to
load the DLL library that is linked without -mno-cygwin on the new
environment, while the DLL linked with -mmo-cygwin works fine. And the
old environment does not seem to have this problem.

I was wondering if anyone have a similar setup and have a working
solution. I am attaching the test programs and execution trace for
your reference. Any information would be greately appreciated.

--Wenchao--

--------------------------------------------
File: HelloNative.java

class HelloNative {
public native static void greeting();
}
---------------------------------------------

File: HelloNative.cc

#include <stdio.h>
#include "HelloNative.h"

extern "C"
JNIEXPORT void JNICALL Java_HelloNative_greeting (JNIEnv *env , jclass
cl)
{
printf ("Hello World!\n");
}
----------------------------------------------

File: Driver.java

public class Driver {
public static void main (String args[]) {

System.out.println ("Loading HelloNative lib...");
System.loadLibrary ("HelloNative");
System.out.println ("OK");

HelloNative.greeting();
}
}
------------------------------------------------

File: Makefile

no-cygwin: clean
javac HelloNative.java
javah HelloNative
gcc -mno-cygwin -Ic:/j2sdk/include -Ic:/j2sdk/include/win32
-Wl,-add-stdcall-alias -shared -o HelloNative.dll HelloNative.cc
javac Driver.java
@echo
java Driver

with-cygwin: clean
javac HelloNative.java
javah HelloNative
gcc -Ic:/j2sdk/include -Ic:/j2sdk/include/win32
-Wl,-add-stdcall-alias -shared -o HelloNative.dll HelloNative.cc
javac Driver.java
@echo
java Driver

clean:
/bin/rm -f *.class *.dll *.o


--------------------------------------------

Trace:
% make no-cygwin
/bin/rm -f *.class *.dll *.o
javac HelloNative.java
javah HelloNative
gcc -mno-cygwin -Ie:/java/j2sdk/include -Ie:/java/j2sdk/include/win32
-Wl,-add-stdcall-alias -shared -o HelloNative.dll HelloNative.cc
javac Driver.java

java Driver
Loading HelloNative lib...
OK
Hello World!

% make with-cygwin
/bin/rm -f *.class *.dll *.o
javac HelloNative.java
javah HelloNative
gcc -Ie:/java/j2sdk/include -Ie:/java/j2sdk/include/win32
-Wl,-add-stdcall-alias -shared -o HelloNative.dll HelloNative.cc
javac Driver.java

java Driver
Loading HelloNative lib...
make: *** [with-cygwin] Error 128
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JNI with Cygwin...library locations Matthew Zimmer Java 4 12-15-2003 07:11 PM
confirm unsubscribe from cygwin@cygwin.com cygwin-help@cygwin.com Python 0 09-05-2003 04:42 PM
WELCOME to cygwin@cygwin.com cygwin-help@cygwin.com Python 1 09-05-2003 07:46 AM
confirm unsubscribe from cygwin-announce@cygwin.com cygwin-announce-help@cygwin.com Python 0 09-05-2003 01:29 AM
confirm unsubscribe from cygwin@cygwin.com cygwin-help@cygwin.com Python 0 09-04-2003 06:34 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57