简体   繁体   English

使用CMake将静态预建库和GLESv2支持添加到Android Studio中的NDK应用

[英]Add static prebuilt libraries and GLESv2 support to NDK app in Android Studio using CMake

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

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. 好的,所以我遇到的第一个问题就是简单地链接静态的预构建库,例如我必须使用的boost的预构建版本。 I've got some success from using the following strategy: 通过使用以下策略,我获得了一些成功:

Add a library as a static prebuilt library that is searched for globally: add_library(boost_thread STATIC IMPORTED GLOBAL) 将库添加为在全球范围内搜索的静态预构建库: add_library(boost_thread STATIC IMPORTED GLOBAL)

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) 设置预建库的位置: set_target_properties(boost_thread PROPERTIES IMPORTED_LOCATION boost/lib/libboost_thread_pthread-gcc-mt-s-1_55.a)

Use stored value for prebuilt library when linking libraries: target_link_libraries(myprog ${boost_thread} ...) 链接库时,请使用预构建库的存储值: 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? 我错过了一步吗?

The second problem is that I can't add the GLESv2 library which I see is also provided by the NDK. 第二个问题是我无法添加NDK也提供的GLESv2库。 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. 我尝试使用find_packagefind_library失败。 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 ). 我在Android.mk中拥有的只是LOCAL_LDLIBS := -lGLESv2 ,因此我尝试进行set(CMAKE_CXX_STANDARD_LIBRARIES ${CMAKE_CXX_STANDARD_LIBRARIES} -lGLESv2)但这都不起作用(给我/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: 我仍然遇到构建问题,但就问题中提出的问题而言,我认为我有不错的解决方案:

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. 这似乎很好。

As for the GLES2 issues I'm using what I placed in the question's comments: 至于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} ...)

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

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