lucaaslb
lucaaslb

Reputation: 1

Calling a C++ shared Library in Ruby

I have a shared library "mylib.so" which was written in C++ and I would like to make an application in Ruby that calls the library functions.

I researched and found FFI (https://github.com/ffi/ffi) and it only works with a C library. With Rice (https://rubygems.org/gems/rice/versions/2.1.0) only I found tutorial that I need to change the source code of the library, but I do not have access to this code.

Is there any way to implement a C++ library in my Ruby code to use its functions?

Upvotes: 0

Views: 764

Answers (1)

Nicola Bernardini
Nicola Bernardini

Reputation: 21

When you say you don't have access to the code, you mean that you do not have access to the headers of the library? If you do not have access to the headers defining classes, prototyping functions and exposing some API, then you wouldn't be able to actually bind this library to any other segment of code, whether the latter is written in c++, python, ruby or whatever.

If you do have access to the headers of the library, then you can easily use rice-ruby to build a ruby wrapper - by following the instructions here. You need only the headers and an up-to-date version of your library in order to do a proper wrap. Feel free to better define your problem and I'll try to help.

Upvotes: 1

Related Questions