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

    
  1. ADD_LIBRARY( libname
  2. [SHARED|STATIC|MODULE]
  3. 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:

    
  1. add_library(native-lib
  2. SHARED
  3. src/main/cpp/first.cpp
  4. src/main/cpp/second.cpp)

cmake_minimum_required

Specifies the lowest version of the CMake compiler

    
  1. 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:

    
  1. TARGET_LINK_LIBRARIES( target library1
  2. <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:

    
  1. target_link_libraries( native-lib
  2. ${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.