我在爲C++做JNI教程,並且能夠成功構建。但是,當我嘗試運行時,出現此錯誤彈出窗口「無法啓動程序C:... \ CLibHelloWorld.dll」。 資源教程我也跟着爲: http://electrofriends.com/articles/jni/jni-part1-java-native-interface/ http://electrofriends.com/articles/jni/part-2-jni-visual-studio-setup-dll-project/由於.dll(JNI)無法啓動程序
我做得不對我這裏的.dll配置?我確實改變了我的「附加包含目錄」,並且我的Java正在工作,因爲我能夠將java.class文件編譯爲.header文件。
我編譯ClibHelloWorld.h文件
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloWorld
* Method: print
* Signature:()V
*/
JNIEXPORT void JNICALL Java_HelloWorld_print
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
我ClibHelloWorld.cpp是:
#include "HelloWorld.h"
#include "jni.h"
#include "stdio.h"
JNIEXPORT void JNICALL Java_HelloWorld_print(JNIEnv *env, jobject obj)
{
printf("Hello world\n");
return;
}
無法啓動程序?我希望只有在嘗試將DLL作爲應用程序啓動時纔會出現這樣的消息。你的命令行是什麼啓動你的測試程序? – user2543253 2015-03-19 10:30:16
我剛剛編譯,構建並運行在Visual Studio 2013最終,然後我得到這個錯誤 – 2015-03-20 14:32:17
Visual Studio只能建立DLL。你不能運行一個DLL。我將寫這個答案。 – user2543253 2015-03-20 15:53:59