JNI + cygwin broken?

W

wenchao Tao

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top