【问题标题】:Could NOT find Boost (missing: python3) (found version "1.76.0") - CMake Windows找不到Boost(缺少:python3)(找到版本“1.76.0”)-CMake Windows
【发布时间】:2021-12-22 21:58:14
【问题描述】:

当我尝试从 ros2 编译 cv_bridge 时,我需要帮助解决这个 cmake boost python3 发现问题,它使用一个名为 colcon 的构建工具,然后是 CMake。 colcon 构建错误信息:

> colcon build --symlink-install --merge-install
...    
--- stderr: cv_bridge
    CMake Error at C:/Program Files/CMake/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
      Could NOT find Boost (missing: python3) (found version "1.76.0")
    Call Stack (most recent call first):
      C:/Program Files/CMake/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
      C:/Program Files/CMake/share/cmake-3.22/Modules/FindBoost.cmake:2360 (find_package_handle_standard_args)
      CMakeLists.txt:32 (find_package)

我尝试过的:

  • 安装不同版本的 boost:1.58、1.67、1.76
  • 将 cv_bridge 的 CMakeLists.txt 中的 boost 库的路径添加到 Boost_INCLUDE_DIRS:
     if(NOT ANDROID)
          find_package(PythonLibs)
          list(APPEND Boost_INCLUDE_DIRS "C:/Program Files/boost/boost_1_76_0")
          list(APPEND Boost_INCLUDE_DIRS "C:/Program Files/boost/boost_1_76_0/stage/lib")
  • libboost_python38-vc142-mt-gd-x64-1_76.lib 重命名为libboost_python38.liblibboost_python3.lib
  • 使用 bootstrap.batb2 从源代码编译 Boost 或使用 zip 文件安装。
  • 在这里和其他地方寻找答案,这导致我尝试了上面的事情

我的想法已经用完了,任何帮助将不胜感激!

【问题讨论】:

  • 尝试配置版本find_package 来定位boost。在使用find_package之前设置Boost_ROOT;或者,将您安装 boost 的目录添加到使用 b2 (.\b2 ... "--prefix=some/path" ... install) 到 CMAKE_PREFIX_PATHfind_package(Boost REQUIRED COMPONENTS python CONFIG)。此外请注意,the FindPythonLibs module 自 cmake 3.12 起已弃用
  • 感谢费边!我尝试设置 Boost_ROOT,为此还需要将策略 CMP0074 设置为 NEW,但没有成功。同样将C:\Program Files\boost\boost_1_76_0 添加到CMAKE_PREFIX_PATH 也不起作用。配置版本也不起作用。配置版本找不到FindPython3Config.cmake,因为它不存在。我发现这个thread 似乎cmake config 停止寻找它告诉它与boost 1.70 及更高版本...

标签: boost cmake windows-10 ros2


【解决方案1】:

我能够使用precompiled Boost 1.74 并将 cv_bridge/CMakeLists.txt 的 boost/python 相关部分更改为:

...
set(BOOST_ROOT <your/path/to/boost_1_74_0>)

find_package (Python3 REQUIRED COMPONENTS Interpreter Development)
if(NOT ANDROID)
    find_package(Boost QUIET)
    if(Boost_VERSION LESS 106500)
        find_package(Boost REQUIRED python)
    else()
        # This is a bit of a hack to suppress a warning
        #   No header defined for python3; skipping header check
        # Which should only affect Boost versions < 1.67
        # Resolution for newer versions:
        #  https://gitlab.kitware.com/cmake/cmake/issues/16391
        if (Boost_VERSION LESS 106700)
            set(_Boost_PYTHON3_HEADERS "boost/python.hpp")
        endif()
        find_package(Boost COMPONENTS python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR} REQUIRED)
    endif()
else()
    find_package(Boost REQUIRED)
endif()
find_package(sensor_msgs REQUIRED)
...

在再次触发 colcon build 之前不要忘记删除 build 和 install 文件夹。

【讨论】:

    相关资源