2016-11-20 115 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)