swig – ruby

Tags:

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

Comments

5 responses to “swig – ruby”

  1. onjo Avatar

    안녕하세요. ^^;
    mkseo님의 (wordPress)블로그에서는
    프로그램 코드들에 syntax highlighting이 적용되어 있는데
    어떤 (wordPress)플러그인을 쓰시는 것인지 알 수 있을까요?

  2. onjo Avatar

    자문자답입니다.. –;
    http://www.chroder.com/archives/2005/04/16/wordpress-codehighlight-plugin/
    를 설치하면 되는군요.. 어쨌든 wordPress에서 syntax highlighting기능을 쓸수있다는
    것을 알게 해주신 mkseo님께 감사드립니다. ^^;

  3. MKSeo Avatar
    MKSeo

    @onjo: 아 네;; 코드를 편하게 출력하고자하는건 모든 프로그래머의 꿈인 듯. 제가보기엔 code highlight 가 가장 좋더라구요.

  4. nohmad Avatar

    swig 관련 검색을 하다가 이 포스트를 발견했습니다. 해결책은 다음과 같은 extconf.rb 파일을 만드는 것입니다.

    $ ls
    extconf.rb person.bundle* person.cpp person.hpp person.i person.o person_wrap.cxx person_wrap.o

    $ cat extconf.rb
    require ‘mkmf’
    create_makefile ‘RubyPerson’

    $ ruby extconf.rb
    creating Makefile

    $ make
    cc -dynamic -bundle -undefined suppress -flat_namespace -L/opt/local/lib -L”/opt/local/lib” -o RubyPerson.bundle person_wrap.o person.o -lruby -lpthread -ldl -lobjc
    /usr/bin/ld: warning multiple definitions of symbol _setregid
    /opt/local/lib/libruby.dylib(process.o) definition of _setregid
    /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libpthread.dylib(setregid.So) definition of _setregid
    /usr/bin/ld: warning multiple definitions of symbol _setreuid
    /opt/local/lib/libruby.dylib(process.o) definition of _setreuid
    /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libpthread.dylib(setreuid.So) definition of _setreuid

    $ irb
    irb(main):001:0> require ‘RubyPerson’
    => true
    irb(main):002:0> p = RubyPerson::Person.new(“John Doe”)
    => #<RubyPerson::Person:0x8b81c>
    irb(main):003:0> p.getName=> “John Doe”

  5. MKSeo Avatar
    MKSeo

    mkmf 가 뭘까 그동안 궁금해왔는데 메이크파일 만드는툴이군요;;;
    감사합니다.

Leave a Reply

Your email address will not be published. Required fields are marked *