简体   繁体   English

如何在Android NDK应用程序中使用GLM

[英]How to use GLM in Android NDK Application

I am currently trying to port my OpenGL application to Android and am stuck on how to import and build GLM http://glm.g-truc.net/ properly. 我目前正在尝试将我的OpenGL应用程序移植到Android,并且我仍然坚持如何正确导入和构建GLM http://glm.g-truc.net/ I have no trouble using GLM in standard C++ apps, however I am pretty new to the NDK. 我在标准C ++应用程序中使用GLM没有问题,但我对NDK很新。 I have tried all other solutions posted around the web with no luck. 我已尝试在网上发布的所有其他解决方案,但没有运气。 Here is what I have so far: 这是我到目前为止:

I am using the latest version of GLM (0.9.4) 我使用的是最新版本的GLM(0.9.4)

My .cpp file contains: 我的.cpp文件包含:

    #include <glm\glm.hpp>

My Android.mk file looks like: 我的Android.mk文件如下所示:

    LOCAL_PATH:= $(call my-dir)

    include $(CLEAR_VARS)

    LOCAL_MODULE    := libgl2jni
    LOCAL_CFLAGS    := -Werror
    LOCAL_SRC_FILES := gl_code.cpp
    LOCAL_LDLIBS    := -llog -lGLESv2

    APP_STL := gnustl_static
    LOCAL_C_INCLUDES += \Development\OpenGL\glm-0.9.4.0\

    include $(BUILD_SHARED_LIBRARY)

**\\Development\\OpenGL\\glm-0.4.0** is the location of the GLM files on my C drive ** \\ Development \\ OpenGL \\ glm-0.4.0 **是我的C盘上GLM文件的位置

Upon building, I receive this error: 在构建时,我收到此错误:

   In file included from jni/gl_code.cpp:28:0,
       \Development\OpenGL\glm-0.94.0\glm\glm.hpp:86:18: fatal error: limits: No such file or directory

This resembles codemonkey's problem https://gamedev.stackexchange.com/questions/47128/android-ndk-build-cant-find-glm-headers where the 'APP_STL := gnustl_static' was suggested. 这类似于codemonkey的问题https://gamedev.stackexchange.com/questions/47128/android-ndk-build-cant-find-glm-headers ,其中建议使用'APP_STL:= gnustl_static'。

It appears that my source files are correctly setup, however there is some sort of compiler problem that I cannot identify. 看来我的源文件设置正确,但是有一些我无法识别的编译器问题。 Any help is greatly appreciated! 任何帮助是极大的赞赏!

Follow this solution if you are using Android Studio. 如果您使用的是Android Studio,请遵循此解决方案。

First , download OpenGL Mathematics library here 首先在这里下载OpenGL数学库

Second , extract and copy folder "../glm/glm" to your project location at "../app/src/main/cpp" 其次 ,将文件夹“../glm/glm”提取并复制到项目位置“../app/src/main/cpp”

Third , on CMakeList.txt, add the following: 第三 ,在CMakeList.txt上,添加以下内容:

# Import the CMakeLists.txt for the glm library
add_subdirectory(glm) # if your CMakeLists is at '../cpp'
# add_subdirectory(src/main/cpp/glm) # if your CMakeLists is at '../app'

# add lib dependencies
target_link_libraries(
# Specifies the target library.
native-lib
# Links the target library to the log library included in the NDK.
GLESv2
glm)

Fourth , on 'buidl.griddle' (Mobile App), make sure you have right path to your CMakeList 第四 ,在'buidl.griddle'(移动应用程序)上,确保你有正确的CMakeList路径

 externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
        }
 }

Fifth , include glm headers to your source file: 第五 ,将glm头包含在源文件中:

// open GL libs
#include <GLES2/gl2.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtx/closest_point.hpp>

Sample is available at android-ndk, see Android Endless Tunnel Game 示例可在android-ndk上找到,请参阅Android Endless Tunnel Game

Sam Hocevar's answer to codemonkeys problem is correct. Sam Hocevar对codemonkeys问题的回答是正确的。 it's not glm that's the problem. 这不是问题所在。 It's the "limits" header file used by glm that's the problem. 这是glm使用的“限制”头文件,这就是问题所在。

If Sam's answer does not solve your problem, try changing the toolchain to an earlier version by adding the following to your Application.mk file: 如果Sam的答案无法解决您的问题,请尝试通过将以下内容添加到Application.mk文件中将工具链更改为早期版本:

NDK_TOOLCHAIN_VERSION=4.4.3

And make sure that the STL includes for your project in Eclipse correspond with the toolchain. 并确保STL包含Eclipse中的项目与工具链相对应。 Go to project->properties->C/C++ General->Paths and Symbols 转到project-> properties-> C / C ++ General-> Paths and Symbols

make sure the following directories are included: 确保包含以下目录:

EDIT : these are only examples; 编辑 :这些只是例子; make sure you use the correct platform and abi 确保使用正确的平台和abi

/Path/To/NDK/sources/platforms/android-9/arch-arm/usr/include
/Path/To/NDK/sources/cxx-stl/gnu-libstdc++/4.4.3/include
/Path/To/NDK/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi-v7a/include

EDIT : remark on first directory removed; 编辑:删除第一个目录的备注; seems glm looks for the limits file provided by the current stl implementation 似乎glm查找当前stl实现提供的限制文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM