an example project using pybind11 to embed python in a C++ executable. There are three basic parts:
- a C++ driver executable (
driver.cpp
) - a small C++ library (
src/mylib.cpp
) that negociates between the driver executable and the python library - a small jax / python library (
mypythonlib.py
)
this project uses jax, so install that first
clone the project recursively
git clone https://github.com/samuelpmish/embedding_python_in_cpp.git --recursive
configure and build with CMake
cd embedding_python_in_cpp
cmake . -Bbuild
cmake --build build
run the driver executable from the base directory (so that the python interpreter
will be able to resolve import mypythonlib
)
% build/driver
starting driver...
(c++) x: 1 2 3
(python) computing dfdx elementwise ...
(c++) f'(x): 1.38177 0.0770037 -2.82886