How can I call C++ functions from within ruby

Viewed 24791

I am an experienced C/C++ developer but I am a novice in Ruby.

How can I call a C++ function from with in Ruby?

4 Answers

To call C++ code from Ruby, you will likely want to build an extension.

If you are an experienced C++ developer, you may feel comfortable with Rice:

https://github.com/jasonroelofs/rice

It uses C++ metaprogramming techniques to simplify writing extensions.

If you were calling into C, you could also use ffi. Calling C++ code is a little more complicated than calling C code due to name mangling and exceptions.

Related