Ryan Davis
3/22/2008 5:30:00 PM
On Mar 22, 2008, at 06:10 , Wladjmir Wlj wrote:
> i 've a problem trying to compile a simple C Extension, that
> actually do
> nothing, only print an hello message.
> If from XCode i create and build a new Ruby C Extension, then i try to
> recall it from a ruby script, that use the ruby interpreter compiled
> from MacPort , a BUS ERROR is returned, au contraire, if i use the
> Leopard's ruby interpreter, it works.
> Already tried to change the XCode project target properties to 32 and
> 64bit but no way to work with that ,and i do non understand why, 2
> ruby
> interpreters can't use the same c extension.
2 different ruby interpreters, built in entirely different ways, are
not necessarily compatible with each other. You need to build each and
every extension for a specific interpreter. Take a look at how inline
works:
> #!/usr/bin/ruby -w
>
> require 'rubygems'
> require 'inline'
>
> class Demo
> inline(:C) do |builder|
> builder.c 'void hello() { puts("hello"); }'
> end
> end
>
> Demo.new.hello
>
> # % ./blah.rb
> # hello
>
> # % ruby -d blah.rb
> # RubyInline v 3.6.6
> # Building /Users/ryan/.ruby_inline/Inline_Demo_5d41.bundle with 'cc
> -arch ppc -arch i386 -pipe -bundle -undefined dynamic_lookup -fno-
> common -arch ppc -arch i386 -Os -pipe -fno-common -I /usr/lib/ruby/
> 1.8/universal-darwin9.0 -I /usr/include -o "/Users/ryan/.ruby_inline/
> Inline_Demo_5d41.bundle" "/Users/ryan/.ruby_inline/
> Inline_Demo_5d41.c" -flat_namespace -undefined suppress'
> # Output:
> # Built successfully
> # hello
Then go look at inline.rb to see what information it gathers and how.