I'm trying to set up a RoR environment for my project on Mac OS X Yosemite 10.10.5. My preliminary setup include:
rvm
ruby-1.9.3-p194
gcc v.4.2
Then, I think everything was all set at that moment. Then I further moved on to the next step to install the gem I need for the project. However, when I actually issued the command "gem install ffi -v '1.9.3'", I was getting an error as below
MacBook-Pro:demo-project apple$ sudo gem install ffi -v '1.9.3'
Password:
Building native extensions. This could take a while...
ERROR: Error installing ffi:
ERROR: Failed to build gem native extension.
/Users/apple/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -r ./siteconf20160429-33780-1iddmww.rb extconf.rb
checking for ffi.h... *** 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
--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=/Users/apple/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
--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
/Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:931:in `block in have_header'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:930:in `have_header'
from extconf.rb:16:in `<main>'
extconf failed, exit code 1
Gem files will remain installed in /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/gems/ffi-1.9.3 for inspection.
Results logged to /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/extensions/x86_64-darwin-14/1.9.1/ffi-1.9.3/gem_make.out
and as the error suggested, I then looked into the file mkmf.log in hope to get some useful information for possible corrective action.
cat /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/extensions/x86_64-darwin-14/1.9.1/ffi-1.9.3/mkmf.log
package configuration for libffi is not found
"gcc-4.9 -o conftest -I/Users/apple/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/x86_64-darwin14.5.0 -I/Users/apple/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/backward -I/Users/apple/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1 -I. -I/usr/local/opt/libyaml/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -g -O3 -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -fno-common -pipe conftest.c -L. -L/Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib -L/usr/local/opt/libyaml/lib -L. -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L/usr/local/lib -lruby.1.9.1 -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */
From there, I discovered the command basically try to link to the wrong compiler (gcc-4.9) - I had the version 4.9 installed before, but finally decided to remove it as understanding gcc-4.2 should work fine in my case. Then the next idea that came to my mind was to get it to work by symbolic linking my installed gcc-4.2 (/usr/local/bin/gcc-4.2) to /usr/local/bin/gcc-4.9. and surprisingly, it seemed to work as shown below this time.
MacBook-Pro:demo-project apple$ sudo gem install ffi -v '1.9.3'
Password:
Building native extensions. This could take a while...
Successfully installed ffi-1.9.3
1 gem installed
However, the thing is I really don't want to do a little hack like that as considered that could bring me more problems sooner or later. Anyone could tell me how I can get the "gem install ffi" command to link to the correct compiler in this case? I currently have got no idea where to look. Thanks for your kind help, appreciated!