首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >只有头的C++库不能用Android-NDK编译

只有头的C++库不能用Android-NDK编译
EN

Stack Overflow用户
提问于 2011-09-16 02:23:29
回答 4查看 4.5K关注 0票数 5

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

代码语言:javascript
复制
LOCAL_CFLAGS += -I/Users/Johannes/Development/glm_include/

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

代码语言:javascript
复制
APP_STL := stlport_static

代码语言:javascript
复制
APP_STL := gnustl_static

分别使用。没有什么是有帮助的;这些是我在包含<glm/glm.h>和使用glm::ivec2时得到的错误。ndk-build输出:

代码语言:javascript
复制
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)

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-10-15 21:37:19

不知何故,我设法编译了它。在Application.mk中指定以下选项起到了作用:

代码语言:javascript
复制
APP_OPTIM := release
APP_STL := stlport_static
LOCAL_ARM_MODE := thumb
APP_ABI := armeabi armeabi-v7a 

而且,我认为对于STLport,您不能使用RTTI或Exception,所以不要在Android.mk中启用-frtti-fexceptions

票数 2
EN

Stack Overflow用户

发布于 2012-09-27 05:06:44

经过一些头跳转之后,我想出了如何用GNU libstdc++运行时来修复这个问题。

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

代码语言:javascript
复制
#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()等。

票数 3
EN

Stack Overflow用户

发布于 2011-09-16 03:45:01

尝试构建一个小示例测试应用程序,如下所示:

代码语言:javascript
复制
#include <glm/glm.h>
int main(int argc, char* argv[])
{
    return 0;
}

这行得通吗?

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

一种可能的解决方案是将glm.h include移到任何其他#includes和/或#定义之前,如果您将其设置为文件中的第一件事,则可以绕过该问题。

一个更好的解决方案是尽量避免#定义并尽可能使用内联函数。

我希望这能帮到你。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7435602

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档