From: Gary Date: 2007-10-21T00:20:02+09:00 Subject: Re: Building an extension in C++ Thank you mental!!! It works. I should have figured it out myself, but I needed your help. I'm I bit confused about a C-linkage interface to the C++ portion. Is this going to be more than wrapping the C++ calls in try catch(...) In other words having something like extern "C" VALUE t_init(VALUE self) { //declare any Ruby C++ data conversion vars in C try { //call C++ functions } catch(...) { //process exceptions } //Do any data interactions between C++ and Ruby } Once again, thanks! I spent several hours stumped. -Gary On Oct 19, 3:33 pm, MenTaLguY wrote: > On Sat, 20 Oct 2007 07:15:05 +0900, Gary wrote: > > I'm using cygwin to try to build an extension in C++. I've stripped > > down the pickaxe book's example (http://www.rubycentral.com/pickaxe/ > > ext_ruby.html) to the bare minimum. It looks like: > > > #include "ruby.h > > > VALUE cTest; > > > void Init_Test() { > > cTest = rb_define_class("Test", rb_cObject); > > } > > Although it is not the source of the problem with the shared object > not being found, you need to declare Init_Test with C linkage > (extern "C"), or else Ruby will not be able to find the entry point. > > Besides this, though, safe handling of C++ and Ruby exceptions is > extremely difficult when writing an extension in C++. You should > probably consider writing the Ruby-facing portion of extension in > C, with a C-linkage interface to the C++ portion of the extension, > and be sure to intercept any C++ exceptions before they can cross > into C or Ruby and create havoc. Similarly, C++ code should not > raise Ruby exceptions or call anything which could raise them. > > -mental