- Create binding for a simple function
#include<pybind11/pybind11.h>
int add(int i, int j) {
return i + j;
}
PYBIND11_MODULE(example, m) {
m.doc() = "pybind11 example plugin"; // optional module docstring
m.def("add", &add, "A function which adds two numbers");
}
- Make
g++ -O3 -Wall -shared -std=c++11 -fPIC \
`python3 -m pybind11 --includes` \
example.cpp -o example`python3-config --extension-suffix`
- Call from python
import example
example.add(2,3)