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 ) {
using namespace boost::python;
class_ > ("v1_double")
.def(vector_indexing_suite > ());
class_ > > ("v2_double")
.def(vector_indexing_suite > > ());
//此处,python端需要的是三重vector的数据结构,这里也要把单vector,二重vector都写上,如上
class_ > > > ("v3_double")
.def(vector_indexing_suite > > >());
// 一般函数
def( "main_o", main_o );
}



