5

我想在 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

4 回答 4

3

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.

于 2012-09-26T21:06:43.913 回答
2

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

于 2011-10-15T13:37:18.753 回答
1

尝试构建一个像这样的小型示例测试应用程序:

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

那样有用吗?

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.

于 2011-09-15T19:45:00.990 回答
0

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).

于 2011-10-01T23:25:58.383 回答