2011-03-22 85 views
1

我已經嘗試終端(OSX 10.6.6)中的以下命令,並最終出現錯誤。有誰知道如何解決這個問題?無法安裝JSON與寶石

 
sudo gem install json 

Building native extensions. This could take a while... 
ERROR: Error installing json: 
    ERROR: Failed to build gem native extension. 

     /usr/local/bin/ruby extconf.rb 
checking for ruby/re.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 
    --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 
/usr/local/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError) 
You have to install development tools first. 
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp' 
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:834:in `block in have_header' 
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for' 
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone' 
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:254:in `open' 
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone' 
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:254:in `open' 
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:276:in `postpone' 
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for' 
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:833:in `have_header' 
    from extconf.rb:17:in `' 


Gem files will remain installed in /usr/local/lib/ruby/gems/1.9.1/gems/json-1.5.1 for inspection. 
Results logged to /usr/local/lib/ruby/gems/1.9.1/gems/json-1.5.1/ext/json/ext/generator/gem_make.out 

回答

0

您將需要安裝XCode。它可在AppStore上

如果安裝了Xcode和您仍然收到此錯誤,也許你應該嘗試使用RVM

+0

嗨,感謝您的回覆。我已經安裝了XCode(一個附帶雪豹OSX安裝光盤)。 – katsuya 2011-03-22 21:59:06

+0

你使用macports安裝ruby 1.9.1嗎? – Shiv 2011-03-22 22:05:37

+0

不,我用rvm。它可能是一個問題嗎? – katsuya 2011-03-22 22:17:11

0

你得到這個錯誤的原因是因爲json的寶石包括C/C++的擴展需要在你的機器上編譯才能運行。

只需安裝XCode就不會修復它,您需要專門安裝XCode命令行工具。這是一個編譯器/連接器工具鏈,包括C/C++編譯器,make等

有到Xcode的圖形用戶界面內的菜單內安裝它們的選項,看到這個線程的詳細信息:

Xcode 4.4 and later install Command Line Tools

0

你應該可以通過運行得到所需的安裝工具:

> xcode-select --install