Advertisement
Guest User

Untitled

a guest
Nov 4th, 2012
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. /* file example.c */
  2. int fact(int n) {
  3. if (n <= 1) return 1;
  4. else return n*fact(n-1);
  5. }
  6.  
  7. /* file example.i */
  8. %module example
  9. %{
  10. extern int fact(int n);
  11. %}
  12. extern int fact(int n);
  13.  
  14. /* file extconf.rb */
  15. require 'mkmf'
  16. create_makefile('example')
  17.  
  18. /* file test.rb */
  19. require 'example'
  20. puts Example.fact(4)
  21.  
  22. /* sent into terminal stdin from the directory all these files are in */
  23. $ swig -ruby example.i
  24. $ ruby extconf.rb
  25. creating Makefile
  26. $ make
  27. compiling example_wrap.c
  28. compiling example.c
  29. linking shared object example.so
  30. $ ruby test.rb
  31. /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- example (LoadError)
  32. from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
  33. from test.rb:1:in `<main>'
  34.  
  35. /* versions (output) */
  36. $ ruby --version
  37. ruby 1.9.3p286 (2012-10-12 revision 37165) [x86_64-linux]
  38. $ swig -version
  39.  
  40. SWIG Version 2.0.8
  41.  
  42. Compiled with g++ [x86_64-unknown-linux-gnu]
  43.  
  44. Configured options: +pcre
  45.  
  46. Please see http://www.swig.org for reporting bugs and further information
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement