当我从Java调用一个dll时,出现了这个错误。
这是我的用于dll的c代码。
我使用gcc编译器生成dll。
对于MinGW,我使用以下命令:
gcc -Wl,--add-stdcall-alias -I"\include" -I"\include\win32" -shared -o hello.dll HelloJNI.c
我已经移除了包中的dll文件,但在执行时出现了以下错误。
Exception in thread "main" java.lang.UnsatisfiedLinkError: dll.HelloJNI.sayHello()V
at dll.HelloJNI.sayHello(Native Method)
at dll.HelloJNI.main(HelloJNI.java:7)
这是我的Java代码
public class HelloJNI {
public static void main(String[] args) {
HelloJNI h = new HelloJNI();
h.sayHello(); // invoke the native method
}
static {
try{
System.load("D://Program Files//Java//jdk1.7.0_40//bin//hello.dll"); // hello.dll (Windows) or libhello.so (Unixes)
}
catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
private native void sayHello();
}
这是我的用于dll的c代码。
我使用gcc编译器生成dll。
对于MinGW,我使用以下命令:
gcc -Wl,--add-stdcall-alias -I"\include" -I"\include\win32" -shared -o hello.dll HelloJNI.c
#include <jni.h>
#include <stdio.h>
#include "HelloJNI.h"
JNIEXPORT void JNICALL Java_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) {
printf("Hello World!\n");
return;
}
我已经移除了包中的dll文件,但在执行时出现了以下错误。
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x610d70b4, pid=1720, tid=1160
#
# 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
#
# 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.
#