I need to use a gem from MacRuby (ruby-keychain), and this gem uses FFI.
But it looks like FFI is not working from MacRuby.
Using the irb console, it works fine :
cobalt:~ charbon$ irb
irb(main):001:0> require 'ffi'
=> true
irb(main):002:0> module MyLib
irb(main):003:1> extend FFI::Library
irb(main):004:1> ffi_lib 'c'
irb(main):005:1> attach_function :puts, [ :string ], :int
irb(main):006:1> end
=> #<FFI::Function address=0x007fff8be0197b>
irb(main):007:0> MyLib.puts 'Hello, World using libc!'
Hello, World using libc!
But as soon as i switch to the macirb console (the one provided by Macruby), it fails
cobalt:~ charbon$ macirb
irb(main):001:0> require 'ffi'
=> true
irb(main):002:0>
=> nil
irb(main):003:0> module MyLib
irb(main):004:1> extend FFI::Library
irb(main):005:1> ffi_lib 'c'
irb(main):006:1> attach_function :puts, [ :string ], :int
irb(main):007:0> end
NoMethodError: undefined method `ffi_lib' for MyLib:Class
The gem FFI is installed on the system
cobalt:~ charbon$ macgem list
*** LOCAL GEMS ***
corefoundation (0.1.4)
ffi (1.9.0)
ruby-keychain (0.1.1)
I've search all I could about that.
https://github.com/MacRuby/MacRuby/blob/master/lib/ffi.rb says FFI is built into MacRuby
found few posts on the net with same question but no answer (just put one, not enough rep for more) https://github.com/kreynolds/phidgets-ffi/issues/4
Hope somebody can help ! I'm working with os X 10.8.3, ruby 1.9.3, macruby 1.9.2
Try the phidgets_native gem instead - there's no FFI requirement and it runs fine on OSX (In fact it was developed on it). It's newer, faster, and much more stable. (Plus it supports arm)