添加日志时 CMakeLists.txt (target_link_libraries) 中的 CMake 错误

Raf*_*afa 3 android cmake android-ndk

我有一个带有 CMakeLists.txt 的 ndk 项目,看起来像这样

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror")

add_library( # Specifies the name of the library.
        main

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        main.c)

target_link_libraries(
        android
        log
)
Run Code Online (Sandbox Code Playgroud)

它遵循 googlesamples github repo 上列出的所有 NDK 示例项目中列出的模式。我不断得到CMake Error at CMakeLists.txt (target_link_libraries),似乎大多数人都在用这条线解决它

add_library(debug <files Name>)
Run Code Online (Sandbox Code Playgroud)

但没有人将其添加到日志记录中。我究竟做错了什么?

shi*_*hen 5

将下面添加到您CMakeLists.txttarget_link_libraries.

find_library( # Sets the name of the path variable.
          log-lib

          # Specifies the name of the NDK library that
          # you want CMake to locate.
          log )
Run Code Online (Sandbox Code Playgroud)

然后修改target_link_libraries如下链接android日志

target_link_libraries( # Specifies the target library.
                   main

                   # Links the target library to the log library
                   # included in the NDK.
                   ${log-lib} )
Run Code Online (Sandbox Code Playgroud)