我试图在Mac OS X Yosemite 10.10.5上为我的项目设置一个RoR环境。 我的初步设置包括:
rvm
ruby-1.9.3-p194
gcc v.4.2
然后,我觉得那一刻一切都准备好了。然后我进一步继续下一步安装我需要的项目宝石。 但是,当我实际发出命令" gem install ffi -v' 1.9.3'"时,我得到了 如下错误
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
并且随着错误的建议,我随后查看了文件mkmf.log,希望获得一些有用的信息,以便采取可能的纠正措施。
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 */
从那里,我发现命令基本上尝试链接到错误的编译器(gcc-4.9) - 我之前安装了4.9版本,但最终决定删除它,因为理解gcc-4.2应该在我的情况下正常工作。 然后,我想到的下一个想法是通过符号链接我安装的gcc-4.2(/usr/local/bin/gcc-4.2)到/usr/local/bin/gcc-4.9来实现它。而且令人惊讶的是,这次似乎如下所示。
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
然而,问题是我真的不想做那样的小黑客被认为可能迟早会给我带来更多问题。 任何人都可以告诉我如何获得&#34; gem install ffi&#34;在这种情况下,命令链接到正确的编译器?我目前不知道在哪里看。 谢谢你的帮助,谢谢!