Skip to main content

pybind11

Geoffrey Hunter
mbedded.ninja Author

Overview

pybind11 is a tool which can be used to create Python bindings to C++ code. The 11 in it's name is taken from the C++11 standard, because it makes use of C++11 language features to provide it's functionality (and hence C++11 is the oldest C++ standard it supports).

Unlike some other binding creating software packages that expect to define general type conversion rules and C++ classes to create bindings for in separate interface files (such as Swig), pybind11 expects you to describe your binding interface in the C++ files themselves.

Examples

See https://github.com/gbmhunter/BlogAssets/tree/master/Programming/pybind11/cmake_example for a working example showing how to build Python bindings to C++ code maintained with the CMake build system.

There are other great examples created by pybind themselves, including a plain C++ example and a CMake project example.