0.01
The project is in a healthy, maintained state
ruby-bindgen reads C and C++ headers with libclang and emits Ruby bindings. It supports three output formats: Rice C++ source for high-fidelity C++ wrappers, raw FFI for plain C libraries, and CMake build files to compile the generated extensions. Bindings are driven from a YAML configuration that controls header matching, symbol filtering, name mapping, and version guards. Battle-tested against OpenCV (thousands of classes) and PROJ.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

Runtime

>= 1.16
>= 0.16.0
 Project Readme

ruby-bindgen

ruby-bindgen generates Ruby bindings from C and C++ header files. It can even generate a CMake build system if needed. It has been battle-tested against large C/C++ libraries such as Proj and OpenCV.

Traditionally, wrapping large C and C++ libraries for use in Ruby has been a long, arduous task, especially for large, complex libraries . As a result, many C/C++ libraries are either never exposed to Ruby or their bindings quickly become outdated, especially in scientific and technical domains.

For much more information, read the extensive documentation.

Quick Start

Create a config file (rice-bindings.yaml):

project: my_extension
input: ./include
output: ./ext/generated
format: Rice

match:
  - "**/*.hpp"

clang:
  args:
    - -I./include
    - -std=c++17
    - -xc++

Generate bindings:

ruby-bindgen rice-bindings.yaml

This produces .cpp, .hpp, and .ipp files ready to compile as a Ruby extension.

Relative paths (./include, ./ext/generated, -I./include) are resolved relative to the config file's directory, so you can run ruby-bindgen from anywhere.

Install

gem install ruby-bindgen

Requirements

  • Ruby 3.2+
  • libclang from LLVM/Clang 17 or newer

Documentation

Full documentation is at ruby-rice.github.io/ruby-bindgen.

Real-world bindings

These projects use ruby-bindgen to generate their Ruby bindings:

  • BitmapPlusPlus-ruby — C++ bitmap library, fully automated end-to-end example.
  • proj4rb — bindings for the PROJ cartographic projections C library.
  • opencv-ruby — bindings for OpenCV (thousands of classes, tens of thousands of methods).

License

BSD-2-Clause