如何通过vcpkg降级Python3包并解决CMake检测异常
- 已通过vcpkg安装Python 3.10,需降级至3.7并确保boost等依赖包同步适配
- 此前手动指定Python路径的方式无法影响依赖包,代码如下:
set(Python_LIBRARY "c:/python37/libs/python37.lib") set(Python_INCLUDE_DIR "c:/python37/include/")
按照方案在CMake文件所在项目目录创建vcpkg.json:
{ "name": "confstruct", "version-string": "1.0.0", "builtin-baseline": "98f8d00e89fb6a8019c2045cfa1edbe9d92d3405", "overrides": [ { "name": "python3", "version": "3.7.4" } ], "dependencies": [ { "name": "python3" } ] }
其中:
confstruct取自CMake文件中的project( confstruct )version-string为自定义内容builtin-baseline是vcpkg提示缺失时推荐的值,不清楚该值是否为vcpkg的Git版本,也不确定能否用"recent"这类值替代
CMake相关配置代码:
find_package(Python COMPONENTS Development REQUIRED) message(STATUS "Python:") message(STATUS " Python_INCLUDE_DIRS: ${Python_INCLUDE_DIRS}") message(STATUS " Python_LIBRARIES: ${Python_LIBRARIES}") message(STATUS " Python_LIBRARY_DIRS: ${Python_LIBRARY_DIRS}")
使用Python 3.10时CMake运行正常,但配置版本覆盖后,尽管已安装python37.lib,仍出现如下CMake错误:
CMake Error at C:/prog/cmake-gui/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Python (missing: Development Development.Module
Development.Embed) (found version "2.7")
Call Stack (most recent call first):
C:/prog/cmake-gui/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
C:/prog/cmake-gui/share/cmake-3.22/Modules/FindPython.cmake:561 (find_package_handle_standard_args)
C:/prj-external-libs/vcpkg/scripts/buildsystems/vcpkg.cmake:824 (_find_package)
CMakeLists.txt:34 (find_package)
如何避免CMake找到python37_d.lib?
内容的提问来源于stack exchange,提问作者Zohar Levi

