Rice 1.0.0 - Ruby Interface for C++ Extensions

Rice: Ruby Interface for C++ Extensions

What is Rice?

Rice is a C++ interface to Ruby’s C API. It provides a type-safe and
exception-safe interface in order to make embedding Ruby and writing
Ruby extensions with C++ easier. It is similar to Boost.Python in many
ways, but also attempts to provide an object-oriented interface to all
of the Ruby C API.

What Rice gives you:

  • A simple C+±based syntax for wrapping and defining classes
  • Automatic conversion of exceptions between C++ and Ruby
  • Smart pointers for handling garbage collection
  • Wrappers for most builtin types to simplify calling code

Documentation: http://rice.rubyforge.org
Project Page: http://rubyforge.org/projects/rice

How do you get Rice?

gem install rice

Note: Rice does require a C++ compiler. See the Documentation page for
more details.

How simple of a syntax?

wrapper.cpp

#include “rice/Class.hpp”

class MyWrapper {
public:
MyWrapper() { }

 void doThis() { }
 int doThat(int a, float b) { }

};

extern “C”
void Init_wrapper()
{
define_class(“MyWrapper”)
.define_constructor(Constructor())
.define_method(“do_this”, &MyWrapper::doThis)
.define_method(“do_that”, &MyWrapper::doThat);
}

extconf.rb

require ‘mkmf-rice’
create_makefile(“wrapper”)

test.rb

require ‘wrapper’
c = MyWrapper.new
c.do_this
c.do_that

Building Ruby extensions have never been so easy!

I have error during installation process:
/usr/bin/ld: …/…/rice/librice.a(Class.o): relocation R_X86_64_32
against `a local symbol’ can not be used when making a shared object;
recompile with -fPIC

I’m on 64bit architecture.

Should I file a bug on rubyforge?


Rados³aw Bu³at

http://radarek.jogger.pl - mój blog

2008/2/11 Rados³aw Bu³at [email protected]:

Rados³aw Bu³at

http://radarek.jogger.pl - mój blog

Yeah, go ahead and file a bug. Please include your system information
including gcc version.

Thanks

Jason

On Tue, Feb 12, 2008 at 04:52:12AM +0900, Rados?aw Bu?at wrote:

I have error during installation process:
/usr/bin/ld: …/…/rice/librice.a(Class.o): relocation R_X86_64_32
against `a local symbol’ can not be used when making a shared object;
recompile with -fPIC

I can reproduce this on SuSE 10.1 x86_x64. I’ll see what I can do about
fixing it.

We should have been using the fPIC flag all along, since we’re building
shared objects.

Paul

On Tue, Feb 12, 2008 at 06:20:12AM +0900, Paul B. wrote:

We should have been using the fPIC flag all along, since we’re building
shared objects.

Here’s a patch which you should be able to apply to the tarball:

Index: test/Makefile.am

— test/Makefile.am (revision 173)
+++ test/Makefile.am (working copy)
@@ -32,6 +32,9 @@
-I…
$(RUBY_CPPFLAGS)

+AM_CXXLAGS = \

  •   $(RUBY_CXXFLAGS)
    

AM_LDFLAGS =
$(RUBY_LDFLAGS)
-L…/rice
@@ -41,4 +44,3 @@
$(RUBY_LIBS)
$(RUBY_LIBRUBYARG)

Index: rice/Makefile.am

— rice/Makefile.am (revision 173)
+++ rice/Makefile.am (working copy)
@@ -110,3 +110,5 @@

AM_CPPFLAGS = @RUBY_CPPFLAGS@

+AM_CXXFLAGS = @RUBY_CXXFLAGS@
+
Index: ruby.ac

— ruby.ac (revision 173)
+++ ruby.ac (working copy)
@@ -23,6 +23,7 @@
RUBY_CONFIG_ARCHDIR=RUBY_CONFIG(archdir)
RUBY_CONFIG_LIBDIR=RUBY_CONFIG(libdir)
RUBY_CONFIG_BINDIR=RUBY_CONFIG(bindir)
+RUBY_CONFIG_CFLAGS=RUBY_CONFIG(CFLAGS)
RUBY_CONFIG_LIBS=RUBY_CONFIG(LIBS)
RUBY_CONFIG_DLDLIBS=RUBY_CONFIG(DLDLIBS)
RUBY_CONFIG_LDFLAGS=RUBY_CONFIG(LDFLAGS)
@@ -32,6 +33,12 @@
RUBY_CPPFLAGS="-I${RUBY_CONFIG_ARCHDIR}"
AC_SUBST(RUBY_CPPFLAGS)

+RUBY_CFLAGS="${RUBY_CONFIG_CFLAGS}"
+AC_SUBST(RUBY_CFLAGS)
+
+RUBY_CXXFLAGS="${RUBY_CONFIG_CFLAGS}"
+AC_SUBST(RUBY_CXXFLAGS)
+
RUBY_LDFLAGS="-L${RUBY_ARCHDIR} -L${RUBY_CONFIG_LIBDIR}
${RUBY_LDFLAGS}"
AC_SUBST(RUBY_LDFLAGS)

Rice and the samples now build fine, though two unit tests still fail:

To_From_Ruby:int_from_ruby: integer -4611686018427387904 too small to
convert to int' To_From_Ruby:unsigned_int_from_ruby: integer 13835058055282163712 too big to convert tounsigned int’

We will be sure to test x86_64 better for the next release.

Paul