From: Paul Brannan Date: 2001-12-11T01:31:51+09:00 Subject: [ruby-talk:28098] Re: Boost.Ruby ? On Sun, Dec 09, 2001 at 10:00:34PM +0900, Issac wrote: > I'm starting to wonder about whether it's a good idea to extend > Ruby with C++. When I tried to extend Ruby with a C module, Be sure to read [ruby-talk:17943] (where Chris Uzdavinis makes some good points about exception safety in C++ extensions). > everything went smoothly. As soon as I tried to do it with C++ > everything started falling to pieces. First, gnu c++ complained > about some mismatched parameters even though the code > compiled just fine with gcc: > > Test.cpp: In function `void Init_Test()': > Test.cpp:46: ANSI C++ prohibits conversion from `(long unsigned int)' to `(...)' > > Test.cpp:47: ANSI C++ prohibits conversion from `(long unsigned int, long unsign > ed int)' to `(...)' > make: *** [Test.o] Error 1 You need to make a cast: typedef VALUE (*RUBY_METHOD_FUNC)(); rb_define_method( rb_cMyClass, "foo", RUBY_METHOD_FUNC(foo), -1); > So then I added -fpermissive to the CXXFLAGS in the Makefile. > This got the Test.cpp file to compile, but the linker wasn't pleased: > > Test.exp(.edata+0x30):fake: undefined reference to `Init_Test' > collect2: ld returned 1 exit status > dllwrap: gcc exited with status 1 > make: *** [Test.so] Error 1 > > I think this is because of C++'s name-mangling. In Test.o I found > Init_Test__Fv and _Init_Test__Fv but no Init_Test. Still, I don't > know how to fix this. Try this: extern "C" Init_Test () { ... } Paul