C++ CMake 使用 Python3
CMakeListst 设置
# 如果使用的是非系统目录下的 Python 可以通过指定 Python3_ROOT_DIR 改变查找路径
# set(Python3_ROOT_DIR "${CMAKE_SOURCE_DIR}/venv")
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
add_executable(cpp-python-test main.cpp)
target_include_directories(${PROJECT_NAME} PRIVATE ${Python3_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${Python3_LIBRARIES})
测试代码
#include <Python.h>
int main(