2011-08-27 215 views
0

编辑时,为什么我得到这个错误?

我得到这个错误

1>  Creating library D:\Jni tester\Debug\Jni tester.lib and object D:\Jni tester\Debug\Jni tester.exp 
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup 
1>D:\Jni tester\Debug\Jni tester.exe : fatal error LNK1120: 1 unresolved externals 

当我运行下面的代码:

#include <jni.h> 
#include <stdio.h> 
#include "HelloWorld.h" 

JNIEXPORT void JNICALL 
Java_HelloWorld_print(JNIEnv *env , jobject obj) { 
printf("Hello World!\n"); 
return; 
} 

这是头文件HelloWorld.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 

为什么我得到这个错误?

回答

3

JNIENv应该是JNIEnv(小写n),如Getting Started指南所示。

编辑:从你的错误看来,你应该把项目定义为一个DLL,在你的情况下,它会尝试创建一个可执行文件来寻找主要的方法。

+0

@Jeremy Heiler - 谢谢! – MByD

+0

解析为JNIEnv后,我得到这个错误信息:1>创建库D:\ Jni tester \ Debug \ Jni tester.lib和对象D:\ Jni tester \ Debug \ Jni tester.exp 1> MSVCRTD.lib(crtexe。 obj):错误LNK2019:无法解析的外部符号_main在函数中引用___tmainCRTStartup 1> D:\ Jni tester \ Debug \ Jni tester.exe:致命错误LNK1120:1 unresolved externals'为什么? –

+0

我会在一小时内看它。我得走了。 – MByD

相关问题