JNI + cygwin broken?

Discussion in 'Java' started by wenchao Tao, May 9, 2004.

  1. wenchao Tao

    wenchao Tao Guest

    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
     
    wenchao Tao, May 9, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    462
  2. Replies:
    0
    Views:
    434
  3. WELCOME to

    , Sep 3, 2003, in forum: Python
    Replies:
    1
    Views:
    515
    Robin Becker
    Sep 5, 2003
  4. Replies:
    0
    Views:
    416
  5. Tim McDaniel
    Replies:
    11
    Views:
    329
    Thrill5
    Jan 23, 2009
Loading...

Share This Page