2016-11-20 116 views
1

我得到一个编译错误的下面的头文件:C++为JNI编译错误:未知类型名称的JNIEnv jint JavaVM的

#include <jni.h> 

#ifdef __cplusplus 
extern "C" { 
#endif 

typedef struct { 
    jint x1; 
    jint y1; 
    jint x2; 
    jint y2; 
} Bounds; 

... 

#ifdef __cplusplus 
}; 
#endif 

还有其他的JNI引用,如jobjectJNIEnvJavaVM,等 这并不是抱怨,< jni.h头缺失(这是,但很容易通过添加包含路径修复)。我已经检查过头文件,并在头文件中定义了类型(也是< jni_md.h>)。

这对我没有任何意义。有任何想法吗?

编辑:我忘了包括以下错误文本。

g++ -O2 -fPIC -fpermissive -I. -I.. -I/usr/include -I/usr/local/include/libavcodec -I/usr/local/include/libavdevice -I/usr/local/include/libavformat -I/usr/local/include/libswscale -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers -DUNIX -shared -c -o Plugin.o Plugin.cpp 
clang: warning: argument unused during compilation: '-shared' 
In file included from Plugin.cpp:19: 
In file included from Plugin.h:16: 
Data.h:24:5: error: unknown type name 'jint' 
    jint x1; 
    ^
Data.h:25:5: error: unknown type name 'jint' 
    jint y1; 
    ^
Data.h:26:5: error: unknown type name 'jint' 
    jint x2; 
    ^
Data.h:27:5: error: unknown type name 'jint' 
    jint y2; 
    ^
+2

请您提供完整的错误文字吗? – Leon

+1

可能 - 请参阅http://stackoverflow.com/questions/7212982/ –

+0

@ZabojCampula就像我说的,我没有找到标题的问题,他们被包括在内。 –

回答

1

C代码没有任何明显的错误,这是如果开发环境编译设置正确。因此,怀疑的区域是开发环境,可能是缺少或损坏的JNI头文件。

C编译器提供了选项-E它和编译器仅在应用该选项时才运行预处理器。输出可能被分析包含头文件被发现扩展ifdefs等位置。

预处理器输出显示错误的jni.h文件包含在内。解决方案是正确设置项目包括路径,包括正确的jni.h

0

确实很奇怪。

你可以看看非常相似的代码,可以编译就好在这里:

https://github.com/mkowsiak/jnicookbook/tree/master/recipeNo025 

只是一个句话,你的情况。当您编译代码,不使用

-shared 

你应该使用它,同时建立共享库:

# compile the code 
g++ -O2 -fPIC -fpermissive -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers -DUNIX -c -o c/recipeNo025_HelloWorld.o c/recipeNo025_HelloWorld.cpp 

# make shared lib out of it 
g++ -g -shared c/recipeNo025_HelloWorld.o -o lib/libHelloWorld.$(EXT)