I'm trying to install the ffi gem so that I can use guard-rspec using the command sudo gem install ffi -v '1.9.8'. I end up getting this output:
Building native extensions. This could take a while...
ERROR: Error installing ffi:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby -r ./siteconf20150424-14771-zza3du.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/bin/$(RUBY_BASE_NAME)
--with-ffi_c-dir
--without-ffi_c-dir
--with-ffi_c-include
--without-ffi_c-include=${ffi_c-dir}/include
--with-ffi_c-lib
--without-ffi_c-lib=${ffi_c-dir}/lib
--with-libffi-config
--without-libffi-config
--with-pkg-config
--without-pkg-config
/usr/local/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /usr/local/lib/ruby/2.2.0/mkmf.rb:541:in `try_link0'
from /usr/local/lib/ruby/2.2.0/mkmf.rb:556:in `try_link'
from /usr/local/lib/ruby/2.2.0/mkmf.rb:637:in `try_ldflags'
from /usr/local/lib/ruby/2.2.0/mkmf.rb:1780:in `pkg_config'
from extconf.rb:15:in `<main>'
extconf failed, exit code 1
Gem files will remain installed in /usr/local/lib/ruby/gems/2.2.0/gems/ffi-1.9.8 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/ffi-1.9.8/gem_make.out
The mkmf.log file looks like this:
"/usr/local/bin/gcc -o conftest -I/usr/local/include/ruby-2.2.0/x86_64-darwin14 -I/usr/local/include/ruby-2.2.0/ruby/backward -I/usr/local/include/ruby-2.2.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -pipe conftest.c -L. -L/usr/local/lib -L. -fstack-protector -lruby-static -framework CoreFoundation -lpthread -lgmp -ldl -lobjc "
sh: line 1: 14464 Trace/BPT trap: 5 /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk / -find dsymutil 2> /dev/null
dsymutil: error: unable to find utility "dsymutil", not a developer tool or in PATH
collect2: error: dsymutil returned 72 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
So mkmf.rb seems to be complaining that it can't find dsymutil. But the command /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk / -find dsymutil gives the output
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil
So the problem isn't that I don't have the command line tools installed.
I decided to take a look at the source code for mkmf.rb to see if I could figure out what was going on. The method that raised the error is:
def try_do(src, command, *opts, &b)
unless have_devel?
raise <<MSG
The compiler failed to generate an executable file.
You have to install development tools first.
MSG
end
begin
src = create_tmpsrc(src, &b)
xsystem(command, *opts)
ensure
log_src(src)
MakeMakefile.rm_rf "#{CONFTEST}.dSYM"
end
end
So we can see that the error that gets raised is raised if the method have_devel? returns false. Now check this out:
$ irb
irb(main):001:0> require 'mkmf'
=> true
irb(main):002:0> have_devel?
=> true
Great. So ruby can find my command line tools. But if I run irb as root:
$ sudo irb
Password:
irb(main):001:0> require 'mkmf'
=> true
irb(main):002:0> have_devel?
=> false
It fails. The mkmf.log file that gets spit out is the same as the one above, complaining about lack of dsymutil. I have no idea why this would happen.
Does anybody have any suggestions as to how I could get ffi installed? I suspect that something is weird about my box and nobody will be able to reproduce this mkmf behavior.