Android Studio 找不到 Boost header

标签 android c++ android-studio boost cmake

我有一个 C++ 项目要包含在 Android 项目中。该项目很高兴能够独立构建,但是当使用 Android SDK 工具构建时,在尝试查找 Boost header 时会失败:

CMake Error at /usr/local/Android/SDK/cmake/3.6.4111459/share/cmake-3.6/Modules/FindBoost.cmake:1753 (message):
  Unable to find the requested Boost libraries.
  Unable to find the Boost header files.  Please set BOOST_ROOT to the root
  directory containing Boost or BOOST_INCLUDEDIR to the directory containing
  Boost's headers.

以下变量设置为 CMake 缓存条目和环境变量:

BOOST_ROOT = ~/manual-software/boost/target
BOOST_INCLUDEDIR = ~/manual-software/boost

我已将其范围缩小到 FindBoost.cmake 中的以下几行:

  # Look for a standard boost header file.
  find_path(Boost_INCLUDE_DIR
    NAMES         boost/config.hpp
    HINTS         ${_boost_INCLUDE_SEARCH_DIRS}
    PATH_SUFFIXES ${_boost_PATH_SUFFIXES}
    )

现在奇怪的是,我使用完全相同的 CMake 二进制文件来构建 a) 从 Android Studio 终端,b) 从 Android Studio 构建工具,并得到了两个不同的结果。前者构建正确,后者失败。我在上面的 find_path 摘录下方添加了以下消息:

  message(FATAL_ERROR "
    Boost_INCLUDE_DIR = ${Boost_INCLUDE_DIR}
    _boost_INCLUDE_SEARCH_DIRS = ${_boost_INCLUDE_SEARCH_DIRS}
    _boost_PATH_SUFFIXES = ${_boost_PATH_SUFFIXES}")

现在 a) 的输出:

  Boost_INCLUDE_DIR = /home/chris/manual-software/boost
  _boost_INCLUDE_SEARCH_DIRS = ~/manual-software/boost;~/manual-software/boost/target/include;~/manual-software/boost/target;PATHS;C:/boost/include;C:/boost;/sw/local/include
  _boost_PATH_SUFFIXES = boost-1_61_0;boost_1_61_0;boost/boost-1_61_0;boost/boost_1_61_0;boost-1_61;boost_1_61;boost/boost-1_61;boost/boost_1_61;boost-1_60_0;boost_1_60_0;boost/boost-1_60_0;boost/boost_1_60_0;boost-1_60;boost_1_60;boost/boost-1_60;boost/boost_1_60;boost-1_59_0;boost_1_59_0;boost/boost-1_59_0;boost/boost_1_59_0;boost-1_59;boost_1_59;boost/boost-1_59;boost/boost_1_59;boost-1_58_0;boost_1_58_0;boost/boost-1_58_0;boost/boost_1_58_0;boost-1_58;boost_1_58;boost/boost-1_58;boost/boost_1_58;boost-1_57_0;boost_1_57_0;boost/boost-1_57_0;boost/boost_1_57_0;boost-1_57;boost_1_57;boost/boost-1_57;boost/boost_1_57;boost-1_56_0;boost_1_56_0;boost/boost-1_56_0;boost/boost_1_56_0;boost-1_56;boost_1_56;boost/boost-1_56;boost/boost_1_56;boost-1_55_0;boost_1_55_0;boost/boost-1_55_0;boost/boost_1_55_0;boost-1_55;boost_1_55;boost/boost-1_55;boost/boost_1_55;boost-1_54_0;boost_1_54_0;boost/boost-1_54_0;boost/boost_1_54_0;boost-1_54;boost_1_54;boost/boost-1_54;boost/boost_1_54;boost-1_53_0;boost_1_53_0;boost/boost-1_53_0;boost/boost_1_53_0;boost-1_53;boost_1_53;boost/boost-1_53;boost/boost_1_53;boost-1_52_0;boost_1_52_0;boost/boost-1_52_0;boost/boost_1_52_0;boost-1_52;boost_1_52;boost/boost-1_52;boost/boost_1_52;boost-1_51_0;boost_1_51_0;boost/boost-1_51_0;boost/boost_1_51_0;boost-1_51;boost_1_51;boost/boost-1_51;boost/boost_1_51;boost-1_50_0;boost_1_50_0;boost/boost-1_50_0;boost/boost_1_50_0;boost-1_50;boost_1_50;boost/boost-1_50;boost/boost_1_50;boost-1_49_0;boost_1_49_0;boost/boost-1_49_0;boost/boost_1_49_0;boost-1_49;boost_1_49;boost/boost-1_49;boost/boost_1_49;boost-1_48_0;boost_1_48_0;boost/boost-1_48_0;boost/boost_1_48_0;boost-1_48;boost_1_48;boost/boost-1_48;boost/boost_1_48

和b):

  Boost_INCLUDE_DIR = Boost_INCLUDE_DIR-NOTFOUND
  _boost_INCLUDE_SEARCH_DIRS = ~/manual-software/boost;~/manual-software/boost/target/include;~/manual-software/boost/target;PATHS;C:/boost/include;C:/boost;/sw/local/include
  _boost_PATH_SUFFIXES = boost-1_61_0;boost_1_61_0;boost/boost-1_61_0;boost/boost_1_61_0;boost-1_61;boost_1_61;boost/boost-1_61;boost/boost_1_61;boost-1_60_0;boost_1_60_0;boost/boost-1_60_0;boost/boost_1_60_0;boost-1_60;boost_1_60;boost/boost-1_60;boost/boost_1_60;boost-1_59_0;boost_1_59_0;boost/boost-1_59_0;boost/boost_1_59_0;boost-1_59;boost_1_59;boost/boost-1_59;boost/boost_1_59;boost-1_58_0;boost_1_58_0;boost/boost-1_58_0;boost/boost_1_58_0;boost-1_58;boost_1_58;boost/boost-1_58;boost/boost_1_58;boost-1_57_0;boost_1_57_0;boost/boost-1_57_0;boost/boost_1_57_0;boost-1_57;boost_1_57;boost/boost-1_57;boost/boost_1_57;boost-1_56_0;boost_1_56_0;boost/boost-1_56_0;boost/boost_1_56_0;boost-1_56;boost_1_56;boost/boost-1_56;boost/boost_1_56;boost-1_55_0;boost_1_55_0;boost/boost-1_55_0;boost/boost_1_55_0;boost-1_55;boost_1_55;boost/boost-1_55;boost/boost_1_55;boost-1_54_0;boost_1_54_0;boost/boost-1_54_0;boost/boost_1_54_0;boost-1_54;boost_1_54;boost/boost-1_54;boost/boost_1_54;boost-1_53_0;boost_1_53_0;boost/boost-1_53_0;boost/boost_1_53_0;boost-1_53;boost_1_53;boost/boost-1_53;boost/boost_1_53;boost-1_52_0;boost_1_52_0;boost/boost-1_52_0;boost/boost_1_52_0;boost-1_52;boost_1_52;boost/boost-1_52;boost/boost_1_52;boost-1_51_0;boost_1_51_0;boost/boost-1_51_0;boost/boost_1_51_0;boost-1_51;boost_1_51;boost/boost-1_51;boost/boost_1_51;boost-1_50_0;boost_1_50_0;boost/boost-1_50_0;boost/boost_1_50_0;boost-1_50;boost_1_50;boost/boost-1_50;boost/boost_1_50;boost-1_49_0;boost_1_49_0;boost/boost-1_49_0;boost/boost_1_49_0;boost-1_49;boost_1_49;boost/boost-1_49;boost/boost_1_49;boost-1_48_0;boost_1_48_0;boost/boost-1_48_0;boost/boost_1_48_0;boost-1_48;boost_1_48;boost/boost-1_48;b
oost/boost_1_48

为什么 find_path 的行为不同?

最佳答案

此问题归因于 CMake 的交叉编译安全功能。 CMake 不会查找 CMAKE_FIND_ROOT_PATH 之外的路径,在 Android 交叉编译的情况下,该路径将设置为相关的 SDK 路径。

要使用主机系统中的库(请注意库文件与目标体系结构兼容),您必须允许 find 使用系统根目录和查找根路径:

set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)

在这种情况下,仅需要 CMAKE_FIND_ROOT_PATH_MODE_INCLUDE

关于Android Studio 找不到 Boost header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47552232/

相关文章:

android - 为什么 distinct() 不返回唯一的整数项?

android - 使用 Intent 打开相机

android - 如何在 openfire XMPP 中启用/禁用 LastSeen

c++ - 如何在 for 循环中制作切换按钮?

java - 安卓工作室 : 2 different activities in 1 button

android - "Android Resource File"是什么?

android - 如何从 BroadcastReceiver 调用 Activity 方法?

c++ - [[maybe_unused]] 在成员变量上,GCC 警告(错误地?)该属性被忽略

c++ - 为什么我们在重载 << 运算符而不是重载 = 和 + 运算符时通过引用返回对象?

Android Studio 第一个项目创建/运行错误(Gradle 未能完成执行)