On Wed, 25 Jul 2001, Brett W. Denner wrote: > Both ruby and my extension were compiled with gcc, so I was hoping that this > would work. Are there any technical problems with trying to use a C++ > source file to create an extension, or have I just not stumbled across the > right incantations to make everything work? > > Thanks, > > Brett Denner Two thoughts: 1) Since Chris U. and I have been discussing Ruby/C++ exception-safety issues quite a bit here at work, exception safety is on the brain. (a) If you throw a Ruby exception from a C++ function, any objects on the stack may not get cleaned up properly (solution: whenever possible, create your objects on the heap and register them with the Ruby garbage collector). (b) If you throw a C++ exception in a Ruby extension, then you will get a call to abort() (since you can't throw exceptions from C++ to C). Solution: in any C++ function called from Ruby, you need to wrap the entire function in a try...catch() block that rethrows any C++ exceptions with rb_raise. 2) The more likely solution, I think, is that perhaps the C++ library isn't getting loaded when you run your program. gcc doesn't link with the C++ library, so when you "require" a Ruby extension written in C++ but compiled with gcc, calls to the C++ library will fail. The solution, of course, is to compile with g++ instead (though I'm not sure how to do this using Ruby's mkmf stuff). Paul