【问题标题】:CMake Error at CMakeLists.txt (target_link_libraries) when adding logs添加日志时 CMakeLists.txt (target_link_libraries) 中的 CMake 错误
【发布时间】:2018-10-23 02:47:58
【问题描述】:

我有一个带有 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 repo 中列出的所有 NDK 示例项目中的模式。我不断收到CMake Error at CMakeLists.txt (target_link_libraries),似乎大多数人都在用这条线解决它

add_library(debug <files Name>)

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

【问题讨论】:

  • 请将错误消息本身添加到问题帖子中。短语“CMakeLists.txt (target_link_libraries) 中的 CMake 错误”仅对错误位置有帮助,但对错误推理没有帮助。

标签: android cmake android-ndk


【解决方案1】:

target_link_libraries 行上方添加下面的CMakeLists.txt

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} )

【讨论】:

  • 我不确定这是在哪里正式记录的。但是当你按照 Android Studio 项目创建向导(有原生支持)时,你会自动得到这个类似的CMakeLists.txt
  • 在样本中。它也应该在 CMake 文档中(我不认为链接库的风格是特定于 Android 的)。
【解决方案2】:

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

2) 进入 android studio 并点击 File ==> link c++ project with gradle ==> 选择 build system ndk-build ,然后寻找你首先找到的 .mk 文件。 点击确定,同步项目。

【讨论】:

  • 这是用 cmake 构建的,而不是 ndk-bundle
  • @Rafa,它们都适用于 Cmake 或 ndk,无论您在代码中找到什么,都可以使用它
  • 项目中都不存在。只是 CMakeLists.txt
  • 然后选择Cmake并点击ok syn
猜你喜欢
  • 2013-09-10
  • 1970-01-01
  • 1970-01-01
  • 2016-06-17
  • 2020-12-09
  • 2020-06-08
  • 2017-06-07
  • 2020-01-20
相关资源
最近更新 更多