Version: 0 Author: Chen XiaomoCopy the code
- CMake: cmakelist. TXT file description
- add_library
- cmake_minimum_required
- target_link_libraries
Android Studio has inherited CMake to simplify NDK operations since 2.0, where compilation into libraries is done using cmakelist.txt.
add_library
Requires CMake to generate a library file from the specified source file, whose prototype is
ADD_LIBRARY( libname
[SHARED|STATIC|MODULE]
source1 source2 ... sourceN)
Said one of the first parameter to generate the name of the library, the second parameter choice [SHARED | STATIC | MODULE] one of them, says the generated type library, the third argument for all need to join the library source address. Example:
add_library(native-lib
SHARED
src/main/cpp/first.cpp
src/main/cpp/second.cpp)
cmake_minimum_required
Specifies the lowest version of the CMake compiler
Cmake_minimum_required (VERSION 3.4.1)#Cmake has a minimum VERSION of 3.4.1
target_link_libraries
Specify the required library files for the target. Its prototype is:
TARGET_LINK_LIBRARIES( target library1
<debug | optimized> library2)
The first parameter is the target library file, and the second parameter is the library you want to use in the target library file. Example:
target_link_libraries( native-lib
${log-lib} )
The above means that the existing log-lib library is linked in the native lib library, that is, the contents of the log-lib library can be used in the native lib.