无法写入核心转储。默认情况下,在客户端版本的Windows上不启用迷你转储,而从java调用dll
我在Windows7上使用JDK1.7.040,通过Java调用一个DLL(用GCC编译)。我已将生成的无法写入核心转储。默认情况下,在客户端版本的Windows上不启用迷你转储,而从java调用dll,java,c,java-native-interface,Java,C,Java Native Interface,我在Windows7上使用JDK1.7.040,通过Java调用一个DLL(用GCC编译)。我已将生成的hello.dll复制到我的java/bin目录,并正在从控制台执行HelloJNI.java 我收到此错误: # # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x610d70b4, pid=1956,
hello.dll
复制到我的java/bin
目录,并正在从控制台执行HelloJNI.java
我收到此错误:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x610d70b4, pid=1956, tid=3960
#
# JRE version: Java(TM) SE Runtime Environment (7.0_40-b43) (build 1.7.0_40-b43)
# Java VM: Java HotSpot(TM) Client VM (24.0-b56 mixed mode, sharing windows-x86 )
# Problematic frame:
# C [cygwin1.dll+0xd70b4]
#
# 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:
# D:\workspace\HelloJNI\hs_err_pid1956.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
我的头文件,由java-jni-HelloJNI
生成:
/*不要编辑此文件-它是机器生成的*/
#包括
/*类HelloJNI的头*/
#如果包括了HelloJNI
#定义_包括_HelloJNI
#ifdef_uucplusplus
外部“C”{
#恩迪夫
/*
*类别:HelloJNI
*方法:你好
*签字:()五
*/
JNIEXPORT void JNICALL Java_HelloJNI_sayHello
(JNIEnv*,jobject);
#ifdef_uucplusplus
}
#恩迪夫
#恩迪夫
我的C代码,用gcc-Wl编译,--add stdcall别名-I“d:\Program Files\Java\jdk1.7.0\u 40\include”-I“d:\Program Files\Java\jdk1.7.0\u 40\include\win32”-shared-o hello.dll hellojlni.C
:
#包括
#包括
#包括“HelloJNI.h”
JNIEXPORT void JNICALL Java_HelloJNI_sayHello(JNIEnv*env,jobject thisObj){
printf(“欢迎”);
返回;
}
好吧,这是我对这个问题的解决方案
我用GCC4.9.3在cygwin32上解决了这个问题
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-cygwin/4.9.3/lto-wrapper.exe
Target: i686-pc-cygwin
Configured with: /cygdrive/i/szsz/tmpp/gcc/gcc-4.9.3-1.i686/src/gcc-4.9.3/configure --srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-4.9.3-1.i686/src/gcc-4.9.3
--prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=i686-
pc-cygwin --host=i686-pc-cygwin --target=i686-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --enable-shared --ena
ble-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --with-dwarf2 --with-arch=i686 --wit
h-tune=generic --disable-sjlj-exceptions --enable-languages=ada,c,c++,fortran,java,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-
libatomic --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --enable-libssp --enable-libada --enable-libjava --enabl
e-libgcj-sublibs --disable-java-awt --disable-symvers --with-ecj-jar=/usr/share/java/ecj.jar --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/inc
lude/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id
Thread model: posix
gcc version 4.9.3 (GCC)
java版本在这里
$ java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) Client VM (build 24.60-b09, mixed mode)
; dlltool --output-def HelloJNI.def --kill-at --add-stdcall-alias --dllname HelloJNI.dll HelloJNI.o
EXPORTS
Java_com_tobee_jni_test_HelloJNI_message@8 @ 1
#包括
#包括
#包括“HelloJNI.h”
JNIEXPORT jstring JNICALL Java_com_tobee_jni_test_HelloJNI_消息(JNIEnv*env,jobject obj){
char-buf[128];
sprintf(buf,“这是我的消息\r\n”);
return(*env)->NewStringUTF(env,buf);
}
/*不要编辑此文件-它是机器生成的*/
#包括
/*类com_tobee_jni_test_HelloJNI的头*/
#如果NDEF包含了测试内容
#定义包含的测试
#ifdef_uucplusplus
外部“C”{
#恩迪夫
/*
*类别:com_tobee_jni_test_HelloJNI
*方法:消息
*签字:()五
*/
JNIEXPORT jstring JNICALL Java_com_tobee_jni_test_HelloJNI_消息
(JNIEnv*,jobject);
#ifdef_uucplusplus
}
#恩迪夫
#恩迪夫
看起来您的JNI代码中有一个bug。感谢您的回复Gyro Gearless,我已经添加了我的代码。我相当确定您无法链接到JNI代码的cygwin dll,它与jvm编译和链接的内容不兼容。试试-mno-cygwin
,我搞不懂。请告诉我-mno是什么。@Bala-mno-cygwin是一个编译器标志,在编译/链接jni代码时使用它。
class HelloJNI{
private native String message();
public static void main( String[] args ){
System.out.println("=====>" + new HelloJNI().message());
}
static{
System.loadLibrary( "HelloJNI" );
}
}
#include <jni.h>
#include <stdio.h>
#include "HelloJNI.h"
JNIEXPORT jstring JNICALL Java_com_tobee_jni_test_HelloJNI_message( JNIEnv *env, jobject obj ){
char buf[128];
sprintf(buf, "this is my message\r\n");
return (*env)->NewStringUTF(env, buf);
}
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_tobee_jni_test_HelloJNI */
#ifndef _Included_com_tobee_jni_test_HelloJNI
#define _Included_com_tobee_jni_test_HelloJNI
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_tobee_jni_test_HelloJNI
* Method: message
* Signature: ()V
*/
JNIEXPORT jstring JNICALL Java_com_tobee_jni_test_HelloJNI_message
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif