You will run into a number of problems using Ruby/DL with C++ code:
C++ function names are mangled, but there is no standard for how
this mangling is done. You will need to mangle your function name
in the same way as the C++ implementation on your platform does.
C++ exceptions are not compatible with Ruby exceptions. If your C++
code throws an exception, then your program will have undefined
behavior (it will likely call abort()).
C++ objects have constructors and destructors, and Ruby/DL doesn’t
know how to deal with these. So if your C++ code returns an object
by value, you might be able to get Ruby to wrap it, but getting Ruby
to destruct the object when it is no longer used is a different
C++ has references in addition to pointers. Ruby/DL doesn’t know
how to deal with references, though I suspect they should work
similar to pointers.
You are probably better off using swig instead.
On Fri, Mar 26, 2004 at 12:04:28PM +0900, Bheeshmar Redheendran wrote:
I’m trying to use a C++ shared library from Ruby and wanted to use
Ruby/DL to do it. It seemed straightforward enough, but I can’t seem
to match the signature on the function I want to import.