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

发布于 2024-12-04 23:07:07 字数 4624 浏览 7 评论 0原文

我想在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

月依秋水 2024-12-11 23:07:07

经过一些头文件跳跃之后,我想出了如何使用 GNU libstdc++ 运行时来解决这个问题。

尝试在包含 之前将 _GLIBCXX_USE_C99_MATH 定义为 1,如下所示:

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

包含 < 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:

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

<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 some glm functions like isnan(), isinf(), etc.

土豪我们做朋友吧 2024-12-11 23:07:07

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

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

而且,我认为使用 STLport,您不能使用 RTTI 或异常,因此不要启用 -frttiAndroid.mk 中的 -fexceptions

Somehow I've managed to compile it. Specifying the following options in the Application.mk did the trick:

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

And, I think with the STLport, you can't use RTTI or Exceptions, so don't enable -frtti or -fexceptions in the Android.mk

花桑 2024-12-11 23:07:07

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

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

这有效吗?

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

一个可能的解决方案是将 glm.h include 移到任何其他 #include 和/或 #defines 之上,如果将其作为文件中的第一件事,则可以绕过该问题。

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

我希望这有帮助。

Try building a small sample test app like this:

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

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.

南冥有猫 2024-12-11 23:07:07

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

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

I'm running into the same issue when I try to compile glm against gnustl_static, but I don't have any issues when I try to compile with stlport_static. My only suggestion would be to try declaring an stlport dependency using LOCAL_STATIC_LIBRARIES in your shared library module.

Also, have you tried using stlport_shared? stlport has both shared and static libraries, whereas gnustl only has a static version (but supports exceptions/RTTI).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文