Hi folks, had a question regarding C11/C++11 and ruby interoperability.
Assuming we have a very well written, concurrent, network client library in
C/C++11 I'd like to hear your thoughts on reusing that in ruby say as a
gem. More specifically, say with in RoR.
I'm leaving this vague to welcome thoughts, lessons, best practices from
folks who have attempted or know enough about these topics to comment on.
it’s been some time since I last bridged a C++ library to Ruby (or even
a C library), but it is possible. The important thing to ensure is that
the extension’s Init_*() function is declared as C linkage (“extern
"C"”) so that Ruby’s C extension mechanism finds it. Other than that,
bridging a C++ library to Ruby is not that different from a pure C
library. For an example of how to bridge a C++ library to Ruby, have a
look at this (unfinished) port of wxWidgets 3 to Ruby:
The version of C++ shouldn’t matter, so if you need C++11, ensure you
specify the proper compiler switches when building your library.
Using a library in Rails is no different than using a library in regular
Ruby. Just please don’t make Rails a dependency of your library so that
non-rails users can enjoy it as well.