1、Boost.Python方式
最靠谱的一种方式
这种情况下CMakeLists.txt 的编写:
cmake_minimum_required(VERSION 3.5)
# Find python and Boost - both are required dependencies
find_package(PythonLibs 2.7 REQUIRED)
find_package(Boost COMPONENTS python REQUIRED)
# Without this, any build libraries automatically have names "lib{x}.so"
set(CMAKE_SHARED_MODULE_PREFIX "")
# Add a shared module - modules are intended to be imported at runtime.
# - This is where you add the source files
add_library(hello_ext MODULE hello_ext.cpp)
# Set up the libraries and header search paths for this target
target_link_libraries(hello_ext ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
target_include_directories(hello_ext PRIVATE ${PYTHON_INCLUDE_DIRS})
代码段的编写:
BOOST_PYTHON_MODULE( CL_CBS

本文介绍了使用Boost.Python库将C++代码集成到Python项目中的方法,详细阐述了CMakeLists.txt的配置和代码段的编写过程。
最低0.47元/天 解锁文章
4908

被折叠的 条评论
为什么被折叠?



