Java JNI C 程序适用于 Mingw32 而不适用于 Cygwin64

Java JNI C Program Works fine with Mingw32 and not with Cygwin64

下面给出的 Java JNI 程序在环境 (1) 中运行良好。但是,如果我将环境更改为 (2),则会出错。感谢任何解决此错误的帮助。

Java代码:

package avajjni;
public class AvajJNI {
    static{
    //Environment (1)
    //System.load("D:\cpro\c_jni_library\dist\Debug\MinGW_32-Windows\libc_jni_library.dll");

    //Environment (2)
    System.load("D:/cpro/c_jni_library/dist/Debug/Cygwin_64-Windows/libc_jni_library.dll");
    }
    public native void fnDisplayData();
    public static void main(String[] args) {
        AvajJNI obj = new AvajJNI();
        obj.fnDisplayData();
    }
}

C代码(.c)

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

JNIEXPORT void JNICALL Java_avajjni_AvajJNI_fnDisplayData
  (JNIEnv *env, jobject obj){
    printf("JNI Method Called\n");
}

运行良好的环境 (1):
OS : Windows 8.1 64 位
Javajdk1.8.0_51(32位)
Mingw 32 位
C 编译器选项:-shared -m32 -Wl,--add-stdcall-alias
Netbeans 使用 32 位 Java

运行

环境 (2) 出现错误:
OS : Windows 8.1 64 位
Javajdk1.8.0_51(64位)
Cygwin 64 位
没有编译器选项
"C:\cygwin64\bin" 添加到路径环境变量
Netbeans 使用 64 位运行 Java

错误:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000180126947, pid=7528, tid=20276
#
# JRE version: Java(TM) SE Runtime Environment (8.0_51-b16) (build 1.8.0_51-b16)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.51-b03 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [cygwin1.dll+0xe6947]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

如果需要任何其他信息,请告诉我

我重现问题,然后展示如何解决它:

mdorey@VXD0141 ~/tmp
$ cat avajjni/AvajJNI.java
package avajjni;
public class AvajJNI {
    static{
    //Environment (1)
    //System.load("D:\cpro\c_jni_library\dist\Debug\MinGW_32-Windows\libc_jni_library.dll");

    //Environment (2)
    System.load("C:\cygwin64\home\mdorey\tmp\libc_jni_library.dll");
    }
    public native void fnDisplayData();
    public static void main(String[] args) {
        AvajJNI obj = new AvajJNI();
        obj.fnDisplayData();
    }
}

mdorey@VXD0141 ~/tmp
$ cat AvajJNI.c 
#include "stdio.h"

typedef unsigned long long __int64;
#include "avajjni_AvajJNI.h"

JNIEXPORT void JNICALL Java_avajjni_AvajJNI_fnDisplayData
  (JNIEnv *env, jobject obj){
    printf("JNI Method Called\n");
}

mdorey@VXD0141 ~/tmp
$ javac avajjni/AvajJNI.java

mdorey@VXD0141 ~/tmp
$ javah avajjni.AvajJNI

mdorey@VXD0141 ~/tmp
$ gcc -I /cygdrive/c/Program\ Files/Java/jdk1.8.0_72/include -I /cygdrive/c/Pro
gram\ Files/Java/jdk1.8.0_72/include/win32 -o libc_jni_library.dll -shared Avaj
JNI.c 

mdorey@VXD0141 ~/tmp
$ java avajjni/AvajJNI
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000180185145, pid=8780, tid=7560
#
# JRE version: Java(TM) SE Runtime Environment (8.0_72-b15) (build 1.8.0_72-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.72-b15 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [cygwin1.dll+0x145145]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\cygwin64\home\mdorey\tmp\hs_err_pid8780.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

mdorey@VXD0141 ~/tmp
$ /cygdrive/c/Program\ Files/software.jessies.org/terminator/Resources/salma-ha
yek/.generated/amd64_Cygwin/bin/java-launcher.exe avajjni/AvajJNI
JNI Method Called

mdorey@VXD0141 ~/tmp
$