我想在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)
发布于 2011-10-15 21:37:19
不知何故,我设法编译了它。在Application.mk中指定以下选项起到了作用:
APP_OPTIM := release
APP_STL := stlport_static
LOCAL_ARM_MODE := thumb
APP_ABI := armeabi armeabi-v7a 而且,我认为对于STLport,您不能使用RTTI或Exception,所以不要在Android.mk中启用-frtti或-fexceptions
发布于 2012-09-27 05:06:44
经过一些头跳转之后,我想出了如何用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>从<math.h>中#undef一些宏,否则会隐藏一些glm函数,如isnan()、isinf()等。
发布于 2011-09-16 03:45:01
尝试构建一个小示例测试应用程序,如下所示:
#include <glm/glm.h>
int main(int argc, char* argv[])
{
return 0;
}这行得通吗?
如果是这样,那么我敢打赌,在你的应用程序中,你的glm.h包含在一些与glm中使用的符号发生冲突的#define之后。您的#define可能正在使用sizeof关键字,并在有错误的glm行中替换该关键字。
一种可能的解决方案是将glm.h include移到任何其他#includes和/或#定义之前,如果您将其设置为文件中的第一件事,则可以绕过该问题。
一个更好的解决方案是尽量避免#定义并尽可能使用内联函数。
我希望这能帮到你。
https://stackoverflow.com/questions/7435602
复制相似问题