仅标头 C++库 (GLM) 无法使用 Android-NDK 编译
我想在Android NDK 项目,但出现编译错误。在 Android.mk
中,我添加了标头搜索路径
LOCAL_CFLAGS += -I/Users/Johannes/Development/glm_include/
,并且还尝试通过在 Application.mk
中设置以下内容来使用 STLport 和 GNU-STL 进行编译如 CPLUSPLUS-SUPPORT 文档中所述:
APP_STL := stlport_static
或
APP_STL := gnustl_static
分别。没有任何帮助;这些是我在包含
并使用 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)
I want to use the GLM (glm.g-truc.net) header-only C++ library in an Android NDK project, but I get compile errors. In the Android.mk
, I've added the header search path
LOCAL_CFLAGS += -I/Users/Johannes/Development/glm_include/
and I've also tried to compile using STLport and GNU-STL by setting the following in Application.mk
like described in the CPLUSPLUS-SUPPORT document:
APP_STL := stlport_static
or
APP_STL := gnustl_static
respectively. Nothing helps; Those are the errors I get when including <glm/glm.h>
and using an glm::ivec2
. ndk-build
outputs:
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
I'm using the Crystax NDK r6 (www.crystax.net)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
经过一些头文件跳跃之后,我想出了如何使用 GNU libstdc++ 运行时来解决这个问题。
尝试在包含
之前将_GLIBCXX_USE_C99_MATH
定义为 1,如下所示:
包含< cmath>
,其中又包含
。_GLIBCXX_USE_C99_MATH
宏强制
到#undef
一些来自
的宏,这会否则隐藏一些glm
函数,例如isnan()
、isinf()
等。After a bit of header hopping, I figured out how to fix this with the GNU libstdc++ runtime.
Try defining
_GLIBCXX_USE_C99_MATH
to 1 before including<glm.hpp>
, like this:<glm.hpp>
includes<cmath>
, which in turn includes<math.h>
. The_GLIBCXX_USE_C99_MATH
macro forces<cmath>
to#undef
some macros from<math.h>
which would otherwise hide someglm
functions likeisnan()
,isinf()
, etc.不知怎的,我已经成功地编译了它。在
Application.mk
中指定以下选项可以解决问题:而且,我认为使用 STLport,您不能使用 RTTI 或异常,因此不要启用
-frtti
或Android.mk
中的-fexceptions
Somehow I've managed to compile it. Specifying the following options in the
Application.mk
did the trick:And, I think with the STLport, you can't use RTTI or Exceptions, so don't enable
-frtti
or-fexceptions
in theAndroid.mk
尝试构建一个小型示例测试应用程序,如下所示:
这有效吗?
如果确实如此,那么我敢打赌,在您的应用程序中,您的 glm.h 包含在一些与 glm 中使用的符号发生符号冲突的 #define 之后。您的 #define 可能正在使用 sizeof 关键字,并且在有错误的 glm 行中被替换。
一个可能的解决方案是将 glm.h include 移到任何其他 #include 和/或 #defines 之上,如果将其作为文件中的第一件事,则可以绕过该问题。
更好的解决方案是尽量避免 #defines 并尽可能使用内联函数。
我希望这有帮助。
Try building a small sample test app like this:
Does that work?
If it does, then I'm going to bet that in your app, you have your glm.h include after some #define that has a symbol collision with a symbol that is used in glm. Your #define is probably making use of the sizeof keyword and that is being substituted in the glm lines that have errors.
A possible solution would be to move the glm.h include above any other #includes and/or #defines, if you make it the first thing in the file you may bypass the problem.
A better solution would be to try to avoid #defines and use inline functions whenever possible.
I hope this helps.
当我尝试针对
gnustl_static
编译glm
时,我遇到了同样的问题,但当我尝试使用stlport_static< 编译时,没有任何问题/代码>。我唯一的建议是尝试在共享库模块中使用
LOCAL_STATIC_LIBRARIES
声明stlport
依赖项。另外,您是否尝试过使用
stlport_shared
?stlport
同时具有共享库和静态库,而gnustl
仅具有静态版本(但支持异常/RTTI)。I'm running into the same issue when I try to compile
glm
againstgnustl_static
, but I don't have any issues when I try to compile withstlport_static
. My only suggestion would be to try declaring anstlport
dependency usingLOCAL_STATIC_LIBRARIES
in your shared library module.Also, have you tried using
stlport_shared
?stlport
has both shared and static libraries, whereasgnustl
only has a static version (but supports exceptions/RTTI).