仅头文件C++库(GLM)不能与Android-NDK编译

问题描述:

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

不知怎的,我已经成功地进行编译。指定在Application.mk下列选项奏效了:

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

而且,我觉得跟STLport的,你不能使用RTTI或异常,因此不能够在Android.mk

尝试构建一个小样本的测试应用程序是这样的:

#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

当我尝试编译glm而不是gnustl_static时,我遇到了同样的问题,但是当我尝试使用stlport_static进行编译时,我没有任何问题。我唯一的建议是尝试在共享库模块中使用LOCAL_STATIC_LIBRARIES声明stlport依赖项。

另外,你有没有尝试过使用stlport_sharedstlport具有共享库和静态库,而gnustl仅具有静态版本(但支持异常/ RTTI)。

-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功能等