2011-09-15 100 views
5

我想在Android NDK項目中使用GLM(glm.g-truc.net)頭文件C++庫,但是出現編譯錯誤。在Android.mk,我已經添加了報頭搜索路徑僅頭文件C++庫(GLM)不能與Android-NDK編譯

LOCAL_CFLAGS += -I/Users/Johannes/Development/glm_include/ 

和我也嘗試過使用的STLport和GNU-STL通過像CPLUSPLUS-SUPPORT文檔中描述設置以下在Application.mk編譯:

APP_STL := stlport_static 

APP_STL := gnustl_static 

分別。沒有什麼幫助那些是我在包括<glm/glm.h>和使用glm::ivec2時得到的錯誤。 ndk-build輸出:

Compile++ arm : wbar <= QCARBase.cpp 
In file included from /Users/Johannes/Development/glm_include/glm/glm.hpp:66, 
       from /Users/Johannes/proj/WirtschaftsblattAR/app/android/wbar/jni/QCARBase.cpp:45: 
/Users/Johannes/Development/glm_include/glm/./core/func_common.hpp:240: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.hpp:240: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.hpp:240: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.hpp:251: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.hpp:251: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.hpp:251: error: expected ')' before 'sizeof' 
In file included from /Users/Johannes/Development/glm_include/glm/./core/func_common.hpp:335, 
       from /Users/Johannes/Development/glm_include/glm/glm.hpp:66, 
       from /Users/Johannes/proj/WirtschaftsblattAR/app/android/wbar/jni/QCARBase.cpp:45: 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1202: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1202: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1202: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1217: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1217: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1217: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1228: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1228: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1228: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1240: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1240: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1240: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1253: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1253: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1253: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1268: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1268: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1268: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1279: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1279: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1279: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1291: error: expected unqualified-id before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1291: error: expected ')' before 'sizeof' 
/Users/Johannes/Development/glm_include/glm/./core/func_common.inl:1291: error: expected ')' before 'sizeof' 
make: *** [/Users/Johannes/proj/WirtschaftsblattAR/app/android/wbar/obj/local/armeabi/objs/wbar/QCARBase.o] Error 1 

我使用Crystax NDK R6(www.crystax.net

+0

你試過'LOCAL_C_INCLUDES + = /用戶/ glm_include /的/約翰內斯/開發',而不是LOCAL_CFLAGS? –

+0

是的,這有同樣的效果。編譯器顯然會找到這些文件,因爲上述錯誤出現在包含的文件中。 – j00hi

+0

在包括glm/glm.h之前顯示代碼 – fazo

回答

2

不知怎的,我已經成功地進行編譯。指定在Application.mk下列選項奏效了:

APP_OPTIM := release 
APP_STL := stlport_static 
LOCAL_ARM_MODE := thumb 
APP_ABI := armeabi armeabi-v7a 

而且,我覺得跟STLport的,你不能使用RTTI或異常,因此不能夠在Android.mk

1

嘗試構建一個小樣本的測試應用程序是這樣的:

#include <glm/glm.h> 
int main(int argc, char* argv[]) 
{ 
    return 0; 
} 

運作的?

如果確實如此,那麼我打賭在你的應用中,你的glm.h包含了一些#符號與glm中使用的符號發生符號衝突之後。你的#define可能正在使用sizeof關鍵字,並且在有錯誤的glm行中被替換。

一個可能的解決方案是移動glm.h包括上述任何其他的#includes和/或#define語句,如果你把它在文件中,你可以繞過這個問題的第一件事。

更好的解決方案是儘量避免#defines和使用內聯函數。

我希望這會有所幫助。

+0

我試過了 - 只包括'',但我不斷收到相同的錯誤。它可能是一個編譯器問題?它似乎沒有效果,改變STL庫。 – j00hi

+0

我在NDK應用程序(r5c和r6b)中測試了2.3+(目標API-10)上的GLM,它工作得很好。可能Crystax是個問題? – kibab

0

當我嘗試編譯glm而不是gnustl_static時,我遇到了同樣的問題,但是當我嘗試使用stlport_static進行編譯時,我沒有任何問題。我唯一的建議是嘗試在共享庫模塊中使用LOCAL_STATIC_LIBRARIES聲明stlport依賴項。

另外,你有沒有嘗試過使用stlport_sharedstlport具有共享庫和靜態庫,而gnustl僅具有靜態版本(但支持異常/ RTTI)。

3

-frtti-fexceptions經過一些頭部跳轉之後,我想出瞭如何用GNU libstdC++運行時來解決這個問題。

嘗試包括<glm.hpp>,這樣之前定義_GLIBCXX_USE_C99_MATH至1:

#define _GLIBCXX_USE_C99_MATH 1 
#include <glm/glm.hpp> 

<glm.hpp>包括<cmath>,其又包括<math.h>。該_GLIBCXX_USE_C99_MATH宏力<cmath>#undef<math.h>一些宏,否則將隱藏像isnan()isinf()一些glm功能等