Wrapping C and C++ libraries by hand for use in Ruby has traditionally been a long, arduous task. For large, complex libraries it can take months. 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.
ruby-bindgen's solves this problem by automatically creating 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.
For much more information read the extensive documenation.
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.yamlThis produces .cpp, .hpp, and .ipp files ready to compile as a Ruby extension.
gem install ruby-bindgen- Ruby 3.2+
- libclang (provided by LLVM/Clang)
Full documentation is at ruby-rice.github.io/ruby-bindgen.
BSD-2-Clause