Android JNI/C++/CMake:如何添加和构建相互依赖的 C++ 库? [英] Android JNI/C++/CMake: how to add and build interdependent C++ libraries?

查看:35
本文介绍了Android JNI/C++/CMake:如何添加和构建相互依赖的 C++ 库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 JNI/CMake 的新手.我创建了一个空的 Java/C++/JNI 项目.然后我在 3 个不同的文件夹中添加了 3 个库(= .h 和 .cpp 文件).这是我的项目文件夹的结构:

I am a newbie with JNI/CMake. I created an empty Java/C++/JNI project. Then I added 3 libs (= .h and .cpp files) in 3 different folders. Here is the structure of my project folders:

-cpp (with lib-native.cpp and CMakeLists.txt inside)
--lib1usedbylib3 (with .h/.cpp files inside + CMakeLists.txt)
--lib2usedbylib3 (with .h/.cpp files inside + CMakeLists.txt)
--lib3thatneedslib1and2 (with .h/.cpp files inside + CMakeLists.txt)

现在我需要在 3 个 CMakeLists 文件中编写代码,但我无法做一些工作......我不想使用 GLOB,因为它似乎不被 CMake 推荐,我想列出每个库的所有文件.我想在一个名为 native-lib(构建在 lib-native.cpp 上)的单个库中编译 3 个库

Now I need to write the code in the 3 CMakeLists files, but I don't manage to do something working... I don't want to use GLOB as it seems that is not recommended by CMake, I want to list all the files for each lib. I want to compile the 3 libs in one single lib called native-lib (built on lib-native.cpp)

如果有人能告诉我必须在我的 3 个 CMakeLists 文件中写什么,我将不胜感激.

I would be very grateful if anybody would be able to tell what I have to write in my 3 CMakeLists files.

非常感谢您的帮助!

推荐答案

我会在顶级目录中编写一个 CMakeLists.txt 文件,并包含这样的子目录:

I would write a CMakeLists.txt file in the top directory and include the subdirectories like that:

set(DIRS
    cpp
    lib1usedbylib3
    lib2usedbylib3
    lib3thatneedslib1and2
)

foreach(LIBRARY ${DIRS})
        message("==> CMake generation for ${LIBRARY}...")
        add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${LIBRARY})
endforeach()

然后在每个目录中,创建一个库,最后处理主 CMakeLists 中的构建库以根据需要链接和混合它们.

And then in each directory, create a library, and finally process the build libraries in the main CMakeLists to link and mingle them as you wish.

这篇关于Android JNI/C++/CMake:如何添加和构建相互依赖的 C++ 库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆