I am trying to compile a c++ extension for Ruby, and the compilation does not return an error, but it does not seem to be compiling correctly. What am I doing wrong?
I have the main cpp script foo.cpp:
#include <iostream>
#include <ruby.h>
extern "C"
VALUE cFoo;
void Init_foo(){cFoo = rb_define_class("Foo", rb_cObject);}
and extconf.rb:
require "mkmf"
$libs += " -lstdc++ "
create_makefile("foo")
and within the directory of these files, I did
$ ruby extconf.rb
creating Makefile
$ make
compiling foo.cpp
linking shared-object foo.so
$ ls
Makefile extconf.rb foo.cpp foo.o foo.so
Then, I have a Ruby script test.rb:
#!/usr/bin/env ruby
require "path_to_this_directory/foo"
and I run test.rb
. It returns an error:
... in `require': .../foo.so: undefined symbol: cFoo - .../foo.so (LoadError)
What am I doing wrong?
Environment
- OS: Ubuntu Linux 11.10
- Ruby: 1.9.3