return x + y; } PyObject* pythonAdd(PyObject* self, PyObject* args) { int x, y, g; if (!PyArg_ParseTuple(args, "ii", &x, &y)) { return nullptr; } else { g = add(x, y); return Py_BuildValue("i", g); } } static PyMethodDef pythonMethods[] = { {"add", pythonAdd, METH_VARARGS}, {NULL}, }; static PyModuleDef pythonModule = { PyModuleDef_HEAD_INIT, "sample", "Sample Module", 0, pythonMethods, }; PyMODINIT_FUNC PyInit_sample() { return PyModule_Create(&pythonModule); } #include <pybind11/pybind11.h> int add(int x, int y) { return x + y; } PYBIND11_MODULE(sample, m) { m.doc() = "Sample Module"; m.def("add", &add); }