From: boris Date: 2002-02-02T21:23:55+09:00 Subject: Re: Extending Ruby in C++ On Sat, Feb 02, 2002 at 08:35:15AM +0900, Nathan Weston muttered... : I am trying to write a ruby extension in C++ (specifically, a wrapper around : a small subset of the KDE libraries). I found a few related threads on this : group, and as far as I can tell I am following their suggestions, but I am : having very strange problems. : : I have some C code that sets up the extension, with an Init_Kde function : that does all the rb_define_method and rb_define_class stuff. I link this : with a separate C++ file that looks something like this: : : extern "C" { : VALUE kapp_new(VALUE self) { : KApplication *k = new KApplication(...) : : Data_Wrap_Struct(...) : ... : } : } : : The C++ file is compiled with g++, the C file with gcc, and they are linked : together (along with the KDE and ruby libraries). I migyht be wrong but it would probably be wise to compile all off this with g++, with the extern "C" bits within a cpp file. It might work. : When I use this extension I get a segmentation fault on the call to the : KApplication constructor. If I take the same code and place it in the main : function of a C++ program, it works fine. : : Any suggestions? : : Thanks, : Nathan : Regards, Chris -- +------------------------------------------------------------------+ | Chris Ross | chris@darkrock.co.uk | ctr@ferite.org | | | http://www.darkrock.co.uk | http://www.ferite.org | +------------------------------------------------------------------+ "I like kids, but I don't think I could eat a whole one."