[英]How to use GLM in Android NDK Application
我目前正在尝试将我的OpenGL应用程序移植到Android,并且我仍然坚持如何正确导入和构建GLM http://glm.g-truc.net/ 。 我在标准C ++应用程序中使用GLM没有问题,但我对NDK很新。 我已尝试在网上发布的所有其他解决方案,但没有运气。 这是我到目前为止:
我使用的是最新版本的GLM(0.9.4)
我的.cpp文件包含:
#include <glm\glm.hpp>
我的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 **是我的C盘上GLM文件的位置
在构建时,我收到此错误:
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
这类似于codemonkey的问题https://gamedev.stackexchange.com/questions/47128/android-ndk-build-cant-find-glm-headers ,其中建议使用'APP_STL:= gnustl_static'。
看来我的源文件设置正确,但是有一些我无法识别的编译器问题。 任何帮助是极大的赞赏!
如果您使用的是Android Studio,请遵循此解决方案。
首先 , 在这里下载OpenGL数学库
其次 ,将文件夹“../glm/glm”提取并复制到项目位置“../app/src/main/cpp”
第三 ,在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)
第四 ,在'buidl.griddle'(移动应用程序)上,确保你有正确的CMakeList路径
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}
第五 ,将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>
示例可在android-ndk上找到,请参阅Android Endless Tunnel Game
Sam Hocevar对codemonkeys问题的回答是正确的。 这不是问题所在。 这是glm使用的“限制”头文件,这就是问题所在。
如果Sam的答案无法解决您的问题,请尝试通过将以下内容添加到Application.mk文件中将工具链更改为早期版本:
NDK_TOOLCHAIN_VERSION=4.4.3
并确保STL包含Eclipse中的项目与工具链相对应。 转到project-> properties-> C / C ++ General-> Paths and Symbols
确保包含以下目录:
编辑 :这些只是例子; 确保使用正确的平台和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
编辑:删除第一个目录的备注; 似乎glm查找当前stl实现提供的限制文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.