【问题标题】:CMake: Android Studio native activity project cannot find thirdparty lib outside the project rootCMake:Android Studio 原生活动项目在项目根目录外找不到第三方库
【发布时间】:2020-04-06 11:35:17
【问题描述】:

为了通过 CMake 合并其他开源库,我检查了类似的问题,例如:

Android Studio: Adding a library outside of the project root

但这些都是关于合并 Android-Studio 库项目而不是外部库。

就我而言,我的文件夹结构如下:

  • 第三方
    • 类别
      • MyLib
    • MyAndroidStudio 项目
      • build.gradle
      • settings.gradle
      • ...
      • 应用
        • 构建
        • 源代码
        • build.gradle
        • ...

在项目 CMakeLists.txt 中,然后我添加了这个

target_link_libraries( # Specifies the target library.
        native-lib

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

set (MyLib_DIR ../../../thirdparty/category/MyLib)

# output lib binary
add_subdirectory (${MyLib_DIR} ./MyLib) 

include_directories (${OBOE_DIR}/include)

我从示例代码中了解到,并假设 CMake 源根位于 src/MyAndroidStudioProject/app,因此 MyLib 相应地使用相对路径定位。

但是,构建项目给了我

CMake Error at /path/to/src/MyAndroidStudioProject/app/src/main/cpp/CMakeLists.txt:53 (add_subdirectory):
add_subdirectory given source "../../../thirdparty/category/MyLib"
which is not an existing directory.

我应该如何解决这个问题?我应该在项目中配置其他设置吗?

【问题讨论】:

    标签: android c++ android-studio build cmake


    【解决方案1】:

    好的,我自己解决了。

    相对路径应该是相对于CMakeLists.txt文件,位于

    /path/to/src/MyAndroidStudioProject/app/src/main/cpp/CMakeLists.txt
    

    所以在我的情况下正确的相对路径应该是

    set (MyLib_DIR ../../../../../../thirdparty/category/MyLib)
    

    即,CMakeLists.txt 位于 app 文件夹的下 3 级。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-14
      相关资源
      最近更新 更多