gpt4 book ai didi

Java JNI C 程序适用于 Mingw32,但不适用于 Cygwin64

转载 作者:行者123 更新时间:2023-11-30 17:12:08 28 4
gpt4 key购买 nike

下面给出的 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):
操作系统:Windows 8.1 64位
Java jdk1.8.0_51(32位)
Mingw 32位
C 编译器选项:-shared -m32 -Wl,--add-stdcall-alias
Netbeans 使用 32 位 Java 运行

出现错误的环境(2):
操作系统:Windows 8.1 64位
Java jdk1.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.javapackage 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.javamdorey@VXD0141 ~/tmp$ javah avajjni.AvajJNImdorey@VXD0141 ~/tmp$ gcc -I /cygdrive/c/Program\ Files/Java/jdk1.8.0_72/include -I /cygdrive/c/Program\ Files/Java/jdk1.8.0_72/include/win32 -o libc_jni_library.dll -shared AvajJNI.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-hayek/.generated/amd64_Cygwin/bin/java-launcher.exe avajjni/AvajJNIJNI Method Calledmdorey@VXD0141 ~/tmp$ 

https://stackoverflow.com/a/13640189/18096

关于Java JNI C 程序适用于 Mingw32,但不适用于 Cygwin64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31783516/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com