Библиотека C ++ (GLM) только для заголовков не компилируется с Android-NDK - PullRequest
5 голосов
/ 15 сентября 2011

Я хочу использовать библиотеку C ++ только для заголовков GLM ( glm.g-truc.net ) в проекте Android NDK, но получаю ошибки компиляции.В Android.mk я добавил путь поиска заголовка

LOCAL_CFLAGS += -I/Users/Johannes/Development/glm_include/

, а также попытался скомпилировать с использованием STLport и GNU-STL, установив следующее в Application.mk, как описано в CPLUSPLUS-Поддержка документа:

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 ]

3 голосов
/ 27 сентября 2012

После небольшого скачкообразного изменения заголовка я выяснил, как это исправить с помощью среды выполнения GNU libstdc ++.

Попробуйте определить _GLIBCXX_USE_C99_MATH до 1, прежде чем включать <glm.hpp>, например:

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

<glm.hpp> включает <cmath>, что, в свою очередь, включает <math.h>. Макрос _GLIBCXX_USE_C99_MATH заставляет <cmath> #undef некоторые макросы из <math.h>, которые в противном случае скрывали бы некоторые glm функции, такие как isnan(), isinf() и т. Д.

2 голосов
/ 15 октября 2011

Как-то мне удалось его скомпилировать.Задание следующих опций в Application.mk сделало свое дело:

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

И, я думаю, что с STLport вы не можете использовать RTTI или исключения, поэтому не включайте -frtti или -fexceptions в Android.mk

1 голос
/ 15 сентября 2011

Попробуйте создать небольшое тестовое приложение, например, вот так:

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

Это работает?

Если это так, то я готов поспорить, что в вашем приложении у вас естьВаш glm.h включает после некоторого #define, в котором есть столкновение символов с символом, который используется в glm.Ваш #define, вероятно, использует ключевое слово sizeof, которое подставляется в строки glm с ошибками.

Возможное решение - переместить файл glm.h выше любых других #include и / или #defines, если вы сделаете это первым в файле, вы можете обойти проблему.

Лучшим решением было бы попытаться избежать #defines и по возможности использовать встроенные функции.

Надеюсь, это поможет.

0 голосов
/ 02 октября 2011

Я сталкиваюсь с той же проблемой, когда пытаюсь скомпилировать glm против gnustl_static, но у меня нет проблем, когда я пытаюсь скомпилировать с stlport_static.Мое единственное предложение - попытаться объявить зависимость stlport с помощью LOCAL_STATIC_LIBRARIES в модуле общей библиотеки.

Кроме того, вы пытались использовать stlport_shared?stlport имеет как общие, так и статические библиотеки, тогда как gnustl имеет только статическую версию (но поддерживает исключения / RTTI).

...