From: Issac Date: 2001-12-09T22:00:34+09:00 Subject: [ruby-talk:28024] Re: Boost.Ruby ? 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, 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 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. When I tried compiling FX-Ruby to learn how to extend Ruby with C++, everything compiled but I got the following error message at runtime: hello.rb:3:in `require': dlopen: Win32 error 193 - /usr/local/lib/ruby/site_ruby /1.7/i386-cygwin/fox.so (LoadError) from hello.rb:3 Any ideas? ----- Original Message ----- From: "Joel VanderWerf" To: "ruby-talk ML" Sent: Saturday, December 08, 2001 11:03 PM Subject: [ruby-talk:27996] Re: Boost.Ruby ? > Issac wrote: > > > > Of all the ways to extend Python with C++, my favorite is Boost.Python > > http://www.boost.org/libs/python/doc/ . > > Does something like this exist for Ruby? > > I have written something almost but not quite entirely unlike it ;). To > wit, the CGenerator module in RAA, and the forthcoming (this weekend if > I'm not too lazy) CShadow module. > > Disclaimer: it works with C code, not C++. (I wrote C++ code for two > years, and that's enough. Seriously, though, it would be a good idea for > it to work with C++ as well.) > > CGenerator is a Ruby interface to the Ruby C API. It lets you define and > load methods dynamically, and it does much of the housekeeping > (rb_define_method, argument counts, argument parsing using rb_scan_args, > initialization, declaration of symbols and classes, etc.). What's > especially nice for my applications (and the reason I wrote it) is that > you can generate C code programmatically, based on (in my case) > numerical formulas provided in the executing script. You can also work > with existing C libraries, but probably not well as Boost or SWIG. > CGenerator doesn't currently include anything to parse prototypes, for > example, though generating wrappers from the parser output would be > easy. > > CShadow helps you integrate C and Ruby data in your objects. It's a > mix-in that uses CGenerator to give your Ruby class a "shadow struct", > which is a C struct attached to the object via the Data_Make_Struct > macro and friends. This struct can have various members, called shadow > attributes, which can be C data types or references to Ruby objects. > These attributes are inherited in Ruby subclasses, which can add shadow > attributes of their own. Some of the housekeeping is managed for you: > accessor methods, the new method, type checking and conversion, mark and > free functions, and (this one won't be done for a while) serialization. > > At the moment, these simple C structs, with their associated Ruby > objects, are enough for my purposes, but it would be quite nice to allow > a C++ object as the "shadow" of a Ruby object. It looks like > Boost.Python would be a good source of ideas for this project. > > -- > Joel VanderWerf California PATH, UC Berkeley > mailto:vjoel@path.berkeley.edu Ph. (510) 231-9446 > http://www.path.berkeley.edu FAX (510) 231-9512