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

时间:2018-10-23 02:47:59

标签: 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
)

它遵循googlesamples github存储库中列出的所有NDK示例项目中列出的模式。我不断收到CMake Error at CMakeLists.txt (target_link_libraries),似乎大多数人都用这一行来解决

add_library(debug <files Name>)

,但是没有人添加它来记录日志。我在做什么错了?

2 个答案:

答案 0 :(得分:3)

将以下内容添加到CMakeLists.txt行上方的target_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 )

然后按如下所示修改target_link_libraries以链接android log lib

target_link_libraries( # Specifies the target library.
                   main

                   # Links the target library to the log library
                   # included in the NDK.
                   ${log-lib} )

答案 1 :(得分:-1)

1),在代码源文件夹中查找“ Android.mk”或“ project.mk”之类的内容,然后记住其路径。

2)转到android studio并单击File ==>用gradle链接c ++项目==>选择构建系统ndk-build,然后查找您首先找到的.mk文件。 单击确定,然后同步项目。