问题
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).
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 a library as a static prebuilt library that is searched for globally:
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)
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?
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.
回答1:
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:# 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} ...)
来源:https://stackoverflow.com/questions/40074981/add-static-prebuilt-libraries-and-glesv2-support-to-ndk-app-in-android-studio-us