【问题标题】:CMakeList.txt ${log-lib} not found找不到 CMakeList.txt ${log-lib}
【发布时间】:2022-11-29 13:31:40
【问题描述】:

我正在开发一个安卓应用程序。由于我们在后端使用“C++”,因此我们希望使用“log-lib”库来输出“log”。但是我收到 NOTFOUND 错误。

cmake_minimum_required(VERSION 3.10)

add_library( score_printer

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             src/main/main.cpp
            )


find_library( log-lib
              log )

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

错误信息

C/C++ debug|armeabi-v7a : CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
  Please set them or make sure they are set and tested correctly in the CMake files:
  log-lib
      linked by target "score_printer" in directory project_dir

【问题讨论】:

    标签: cmake


    【解决方案1】:

    由于 log 是 Android NDK 提供的系统库,因此您不需要使用 find_library 找到它。仅链接库就足够了。

    if (ANDROID)
        target_link_libraries(score_printer PRIVATE log)
    endif()
    

    作为类似的示例,相同的逻辑适用于 Windows SDK 提供的 win32 库。

    if (WIN32)
        target_link_libraries(main PRIVATE d3d11)
    endif()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      相关资源
      最近更新 更多