/* file example.c */ int fact(int n) { if (n <= 1) return 1; else return n*fact(n-1); } /* file example.i */ %module example %{ extern int fact(int n); %} extern int fact(int n); /* file extconf.rb */ require 'mkmf' create_makefile('example') /* file test.rb */ require 'example' puts Example.fact(4) /* sent into terminal stdin from the directory all these files are in */ $ swig -ruby example.i $ ruby extconf.rb creating Makefile $ make compiling example_wrap.c compiling example.c linking shared object example.so $ ruby test.rb /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- example (LoadError) from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from test.rb:1:in `
' /* versions (output) */ $ ruby --version ruby 1.9.3p286 (2012-10-12 revision 37165) [x86_64-linux] $ swig -version SWIG Version 2.0.8 Compiled with g++ [x86_64-unknown-linux-gnu] Configured options: +pcre Please see http://www.swig.org for reporting bugs and further information