[英]JVM exits without any error messages when loading compiled DLL
我正在嘗試從 Java 調用 ac 函數。 加載庫(在 Test.java 中)時,會隨機發生兩件事:
奇怪的是,“有時”“已加載的庫”也會被打印出來。 這意味着庫已加載...
我的問題是我該如何解決這個問題? 真正的問題是我不知道我做錯了什么。
dll編譯步驟:
系統信息:
主文件:
package degubi;
public final class Main {
public static void main(String[] args) {
Test.enable();
}
}
庫文件:
package degubi;
public class Test {
static {
System.out.println("Load lib");
System.loadLibrary("BindLib");
System.out.println("Lib loaded");
}
public static native void enable();
}
源文件:
#include "windows.h"
#include "BindLib.h"
JNIEXPORT void JNICALL Java_degubi_Test_enable(JNIEnv* env, jclass clazz) {
}
頭文件:
#define __int64 long long
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class degubi_Test */
#ifndef _Included_degubi_Test
#define _Included_degubi_Test
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: degubi_Test
* Method: enable
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_degubi_Test_enable(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
你用的是哪個 shell 和 C 編譯器? 問題可能來自 C 編譯器和 shell 環境之間的不兼容。
例如,如果您使用 Cygwin 編譯器編譯 DLL,然后在 Windows CMD 上執行二進制文件,則程序可能無法運行(依賴於 cygwin.dll)。
我最終在 Visual Studio 中創建了一個項目並從那里構建它......工作得很好。 仍然不知道是什么導致了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.