the-risk-taker / meson-cmake-pybind11-cpp-python

Code for lighting talk about how pybind11 enables the exposure of a simple C++ API to Python as a module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Meson/CMake ➕ C++ ➕ pybind11 ➕ Python

About

A combination of C++ and Python to expose an simple API written in C++ to Python as a module. Achieved through the use of pybind11, a lightweight header-only library that facilitates the seamless integration of C++11 code with Python.

Dependencies

  • Meson/CMake
  • pybind11
    • for Meson and manual building: pip install pybind11,
    • for CMake: git submodule update --init --recursive --remote
  • C++11 compatible compiler (Clang or GCC on Linux, MSVC on Windows)

Building

Manually

c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) <source.cpp> -o <module_name>$(python3-config --extension-suffix)

Meson

meson setup build-meson
meson compile -C build-meson
python3 main.py build-meson

CMake

cmake -S . -B build-cmake
cmake --build build-cmake
python3 main.py build-cmake

Useful links

About

Code for lighting talk about how pybind11 enables the exposure of a simple C++ API to Python as a module


Languages

Language:C++ 56.9%Language:Meson 21.3%Language:CMake 12.5%Language:Python 9.3%