【问题标题】:Including a static library in CMAKE from a different folder for an Android Project在 CMAKE 中包含来自 Android 项目的不同文件夹的静态库
【发布时间】:2019-01-23 00:05:19
【问题描述】:

我正在尝试将我的 Android NDK cpp 项目(带有 Android.mk 的 ndk-build)转换为 Android Studio 中的 CMAKE。我有一个这样的项目层次结构:

.
├── Module1
│   ├── CMakeLists.txt
│   ├── include
│   │   └── Module1
│   ├── libModule1
│   │   ├── Module1File1.cpp
│   │   └── Module1File2.cpp
│   └── utModule1
├── MyProject
│   ├── CMakeLists.txt
│   ├── MyProject.iml
│   ├── build
│   │   ├── generated
│   │   ├── intermediates
│   │   └── outputs
│   ├── build.gradle
│   ├── proguard-rules.pro
│   └── src
│       │
│       ├── MyProjectFile1.cpp
│       └── MyProjectFile2.cpp
|
└── settings.gradle

Module1 CMakeLists.txt:

cmake_minimum_required(VERSION 3.4.1)
add_library( # Specifies the name of the library.
             Module1

             # Sets the library as a shared library.
             STATIC

             # Provides a relative path to your source file(s).
             libModule1/Module1File1.cpp
             libModule1/Module1File2.cpp )

MyProject CMakeLists.txt:

cmake_minimum_required(VERSION 3.4.1)

add_subdirectory(../MyModule1)

add_library( # Specifies the name of the library.
             MyProject
             # Sets the library as a shared library.
             SHARED
             # Provides a relative path to your source file(s).
             src/MyProjectFile1.cpp
             src/MyProjectFile2.cpp)

target_link_libraries( # Specifies the target library.
        MyProject
        # Dependencies
        MyModule1
        # Links the target library to the log library
        # included in the NDK.
        ${log-lib})

我在构建时看到以下错误:

CMake Error at CMakeLists.txt (add_subdirectory):

如何将 MyModule1 包含到 MyProject 中?

【问题讨论】:

标签: android c++ android-studio cmake static-libraries


【解决方案1】:

建议的修复来自:

Add a dependency not in a subdirectory using CMake

为我工作。

include_directories(../MyMModule1/include/)
add_subdirectory("../MyMModule1/" "${CMAKE_CURRENT_BINARY_DIR}/MyModule1_build")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 2017-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-23
    • 1970-01-01
    相关资源
    最近更新 更多