我在为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