使用CMake将静态预建库和GLESv2支持添加到Android Studio中的NDK应用 [英] Add static prebuilt libraries and GLESv2 support to NDK app in Android Studio using CMake

查看:409
本文介绍了使用CMake将静态预建库和GLESv2支持添加到Android Studio中的NDK应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个分为两部分的问题. 我目前正在将当前的构建设置(Eclipse; ndk-build)转换为(希望)更好的构建设置(Android Studio; cmake). 我走了cmake的道路,因为我读到那是无需进行实验性gradle插件即可进行体面调试正常工作的唯一方法(如果您确定这是错误的,请告诉我).

This is a 2 part question. I'm currently in the process of converting our current build setup (Eclipse; ndk-build) to (hopefully) a better one (Android Studio; cmake). I'm going down the cmake path because I read that that is the only way to get decent debugging to work properly without the need for the experimental gradle plugin (if you are sure this is false, please let me know).

好吧,所以我遇到的第一个问题就是简单地链接静态的预构建库,例如我必须使用的boost的预构建版本. 通过使用以下策略,我获得了一些成功:

Ok so first issue I'm having is simply linking static prebuilt libraries such as a prebuilt version of boost which I kind of have to use. I've got some success from using the following strategy:

将一个库添加为在全球范围内搜索的静态预构建库: add_library(boost_thread STATIC IMPORTED GLOBAL)

Add a library as a static prebuilt library that is searched for globally: add_library(boost_thread STATIC IMPORTED GLOBAL)

设置预建库的位置: set_target_properties(boost_thread PROPERTIES IMPORTED_LOCATION boost/lib/libboost_thread_pthread-gcc-mt-s-1_55.a)

Set the location of the prebuilt library: set_target_properties(boost_thread PROPERTIES IMPORTED_LOCATION boost/lib/libboost_thread_pthread-gcc-mt-s-1_55.a)

链接库时,将存储的值用于预建库: target_link_libraries(myprog ${boost_thread} ...)

Use stored value for prebuilt library when linking libraries: target_link_libraries(myprog ${boost_thread} ...)

当我说我取得了一些成功时,我的意思是我看到一些错误消失了,但其他错误仍然存​​在(尽管它不再抱怨找不到链接的库).我错过了一步吗?

When I say I have had some success, I mean I saw some errors disappear but others remain (although it no longer complains it can't find the library to link). Am I missing a step?

第二个问题是我无法添加NDK也提供的GLESv2库.我似乎也找不到单个来源说明如何正确执行此操作.我尝试使用find_packagefind_library失败. 我在Android.mk中拥有的只是LOCAL_LDLIBS := -lGLESv2,所以我尝试做set(CMAKE_CXX_STANDARD_LIBRARIES ${CMAKE_CXX_STANDARD_LIBRARIES} -lGLESv2),但是那也不起作用(给我/bin/sh: -lGLESv2: command not found).

The second problem is that I can't add the GLESv2 library which I see is also provided by the NDK. I also can't seem to find a single source stating how this should be done correctly. I've tried using find_package and find_library without success. All I have in the Android.mk is LOCAL_LDLIBS := -lGLESv2 and so I tried to do set(CMAKE_CXX_STANDARD_LIBRARIES ${CMAKE_CXX_STANDARD_LIBRARIES} -lGLESv2) but that didn't work either (gives me /bin/sh: -lGLESv2: command not found).

第一个问题应该非常普遍,但是似乎很少有文档说明应如何做.第二个问题也许不太常见,但可能仍然足够普遍,令我惊讶的是,如何设置它几乎没有帮助.

First problem is supposed to be incredibly common and yet there seems to be little documentation explaining how it should be done. The second problem is maybe a little less common but probably still common enough that I'm surprised to find little to no help as to how to set it up.

推荐答案

我仍然遇到构建问题,但就问题中提出的问题而言,我认为我有不错的解决方案:

I'm still having build issues but as far as the issues presented in the question are concerned, I think I have decent solutions:

要包含预构建的静态库,请执行以下操作:
add_library(boost_regex STATIC IMPORTED)
set_target_properties(boost_regex PROPERTIES IMPORTED_LOCATION /full/path/to/libboost_regex.a) # I'm using ${CMAKE_CURRENT_SOURCE_DIR} to determine full path
target_link_libraries(myproject ... boost_regex ...)
这似乎工作正常.

To include a prebuilt static library:
add_library(boost_regex STATIC IMPORTED)
set_target_properties(boost_regex PROPERTIES IMPORTED_LOCATION /full/path/to/libboost_regex.a) # I'm using ${CMAKE_CURRENT_SOURCE_DIR} to determine full path
target_link_libraries(myproject ... boost_regex ...)
This seems to work fine.

关于GLES2问题,我使用的是问题注释中的内容:
# GLESv2 find_path(GLES2_INCLUDE_DIR GLES2/gl2.h HINTS ${ANDROID_NDK}) find_library(GLES2_LIBRARY libGLESv2.so HINTS ${GLES2_INCLUDE_DIR}/../lib) target_include_directories(myproject PUBLIC ${GLES2_INCLUDE_DIR}) target_link_libraries(myproject ... ${GLES2_LIBRARY} ...)

As for the GLES2 issues I'm using what I placed in the question's comments:
# GLESv2 find_path(GLES2_INCLUDE_DIR GLES2/gl2.h HINTS ${ANDROID_NDK}) find_library(GLES2_LIBRARY libGLESv2.so HINTS ${GLES2_INCLUDE_DIR}/../lib) target_include_directories(myproject PUBLIC ${GLES2_INCLUDE_DIR}) target_link_libraries(myproject ... ${GLES2_LIBRARY} ...)

这篇关于使用CMake将静态预建库和GLESv2支持添加到Android Studio中的NDK应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆