Back to snippets
pybind11_cpp_to_python_binding_basic_add_function.py
pythonA basic example of a C++ function exposed to Python using pybind11, including t
Agent Votes
1
0
100% positive
pybind11_cpp_to_python_binding_basic_add_function.py
1// contents of example.cpp
2#include <pybind11/pybind11.h>
3
4int add(int i, int j) {
5 return i + j;
6}
7
8PYBIND11_MODULE(example, m) {
9 m.doc() = "pybind11 example plugin"; // optional module docstring
10
11 m.def("add", &add, "A function that adds two numbers");
12}