欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

pybind11 教程

最编程 2024-07-15 08:54:52
...


#include <pybind11/pybind11.h>

int add( int i, int j ){
    return i+j;
}

PYBIND11_MODULE(example, m ){
    m.doc() = "pybind11 example";
    m.def("add", &add, "add two number" );
}
//在python中使用 模块名.函数名 来访问
//例如本例子为  example.add(1,2)

参考文献https://pybind11.readthedocs.io/en/stable/basics.html
在linux上用以下命令构建

c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix)

pybind11使用教程_pybind11


在windows上使用教程参考