【问题标题】:CMake can not find Boost PythonCMake 找不到 Boost Python
【发布时间】:2022-01-02 16:50:37
【问题描述】:

我正在尝试使用 CMake 3.17.5 构建 3d 方应用程序。

我已通过 vcpkg(在 Windows 上)安装了 boost。我检查了我已经通过 vcpkg 安装了 boost-python。

我在 CMake GUI 中收到以下错误:

CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
  Could NOT find Boost (missing: python) (found version "1.75.0")
Call Stack (most recent call first):
  C:/Program Files (x86)/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files (x86)/CMake/share/cmake-3.17/Modules/FindBoost.cmake:2166 (find_package_handle_standard_args)
  cmake/modules/FindUSDMonolithic.cmake:71 (find_package)
  cmake/defaults/Packages.cmake:34 (find_package)
  CMakeLists.txt:11 (include)

我尝试将 CMAKE_TOOLCHAIN_FILE 设置为 vcpkg.cmake,但没有成功。

注意:在我将 Boost_INCLUDE_DIR 设置为 vcpkg/installed/x64-windows/include/ 后,CMake 确实找到了提升,但它仍然有这个奇怪的错误。如果不设置这个变量,CMake 根本找不到 boost 并且错误是不同的

【问题讨论】:

    标签: cmake vcpkg cmake-gui


    【解决方案1】:

    你应该先找到 Python:

    find_package(Python3 REQUIRED COMPONENTS Development)
    target_include_directories(MyTarget SYSTEM PRIVATE ${Python3_INCLUDE_DIRS})
    
    find_package(Boost REQUIRED COMPONENTS ${BOOST_PYTHON_COMPONENT})
    target_link_libraries(MyTarget PRIVATE Boost::python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR})
    

    【讨论】:

      猜你喜欢
      • 2011-04-18
      • 2011-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-28
      相关资源
      最近更新 更多