仅限标头的C ++库(GLM)无法使用Android-NDK进行编译

时间:2011-09-15 18:23:29

标签: c++ stl android-ndk android-stlport

我想在Android NDK项目中使用GLM(glm.g-truc.net)仅限标头的C ++库,但是我遇到了编译错误。在Android.mk中,我添加了标题搜索路径

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

我还尝试使用STLport和GNU-STL进行编译,方法是在Application.mk中设置以下内容,如CPLUSPLUS-SUPPORT文档中所述:

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

4 个答案:

答案 0 :(得分:3)

经过一些标题跳转后,我想出了如何使用GNU libstdc ++运行时解决这个问题。

在包含_GLIBCXX_USE_C99_MATH之前尝试将<glm.hpp>定义为1,如下所示:

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

<glm.hpp>包含<cmath>,其中包含<math.h>_GLIBCXX_USE_C99_MATH宏强制<cmath> #undef <math.h>来自glm的某些宏,否则会隐藏isnan()isinf()等{{1}}个函数等等。

答案 1 :(得分:2)

不知怎的,我已经成功编译了它。在Application.mk中指定以下选项可以解决问题:

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

而且,我认为使用STLport,您无法使用RTTI或例外,因此请勿在{{1​​}}

中启用-frtti-fexceptions

答案 2 :(得分:1)

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

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

这有用吗?

如果确实如此,那么我打赌在你的应用程序中,你的glm.h包含在一些与glm中使用的符号发生符号冲突的#define之后。你的#define可能正在使用sizeof关键字,并且在有错误的glm行中被替换。

一个可能的解决方案是将glm.h包含在任何其他#includes和/或#defines之上,如果你把它作为文件中的第一件事就可以绕过这个问题。

更好的解决方案是尽量避免使用#defines并使用内联函数。

我希望这会有所帮助。

答案 3 :(得分:0)

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

另外,您是否尝试过使用stlport_sharedstlport有共享库和静态库,而gnustl只有静态版本(但支持例外/ RTTI)。