CMake 找不到 Boost Python

CMake can not find Boost Python

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

我通过 vcpkg 安装了 boost(在 Windows)。我检查过我已经通过 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 根本找不到提升并且错误不同

你应该先找到Python:

find_package(Python3 REQUIRED COMPONENTS Development)
target_include_directories(MyTarget SYSTEM PRIVATE ${Python3_INCLUDE_DIRS})

find_package(Boost REQUIRED COMPONENTS python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR})
target_link_libraries(MyTarget PRIVATE Boost::python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR})