OMG.. I’m dying of swig for c++ and ruby interconnections….
[person.hpp]
#ifndef __PERSON #define __PERSON #include <iostream> #include <string> class Person { std::string name_; public: Person(const std::string& name): name_(name) { } std::string getName(); }; #endif
[person.cpp]
#include "person.hpp" using namespace std; string Person::getName() { return name_; }
[person.i]
%module RubyPerson %{ #include "person.hpp" %} %include "std_string.i" %include "person.hpp"
So far, so good. But…
$ swig -c++ -ruby person.i $ g++ -fpic -c person.cpp person_wrap.cxx -I/usr/lib/ruby/1.8/i486-linux $ g++ -shared person.o person_wrap.o -o rubyperson.so $ irb irb(main):001:0> require "rubyperson.so" LoadError: ./rubyperson.so: undefined symbol: Init_rubyperson - ./rubyperson.so from ./rubyperson.so from (irb):1 from :0 irb(main):002:0> aslfdjklq%j1$@$#1@%!FKLQR!!@#$%K;gjsdf