2012-12-14 82 views
3

我剛買了一臺新的MacBook Pro(顯然是w/ML)。我正在做的第一件事是安裝開發工具。我用rvm安裝了Ruby,並且還安裝了Homebrew。我不得不下載XCode命令行工具。在山獅創建寶石時出錯

$ gcc -v 
Using built-in specs. 
Target: i686-apple-darwin11 
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.11~67/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~67/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1 
Thread model: posix 
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00) 

我能夠安裝mongo寶石很好,但是當我嘗試安裝nokogiri,我收到以下錯誤:

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

     /Users/johnsmith/.rvm/rubies/ruby-1.9.3-p327/bin/ruby extconf.rb 
checking for libxml/parser.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. 

該消息後,它會列出一大堆的配置選項,然後說:

/Users/johnsmith/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/mkmf.rb:369:in `try_do': The compiler failed to generate an executable file. (RuntimeError) 
You have to install development tools first. 

看來我有開發工具,所以我找不出這個問題。有什麼想法嗎?

回答

0

在這種情況下,您需要libxml的開發頭文件,這些頭文件不作爲編譯器工具的一部分提供。通常您需要安裝HomebrewMacPorts之一來幫助安裝這些依賴關係。

這裏的提示是有點難以在噪聲被發現,如果你不熟悉,但就是:

checking for libxml/parser.h... *** extconf.rb failed *** 

.h文件提供的開發包,並有必要進行編譯這些庫的擴展。

+0

謝謝。我在Nokogiri網站上找到了安裝Homebrew 0.9的說明,但仍然遇到同樣的錯誤。也許Homebrew 0.9.3打破了別的東西。我會接下來嘗試MacPorts。 –

3

我不得不四處張望了一會兒,但我找到了解決辦法,在github上: https://github.com/sparklemotion/nokogiri/issues/442#issuecomment-7978408

libxml2的缺失。

我發現這是一個需要額外的步驟,以解決上述的家釀 0.9在Mac OS X 10.8山獅,那就是創建一個「/usr/bin/gcc-4.2」鏈接:

brew install libxml2 libxslt 
brew link libxml2 libxslt 
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz 
tar xvfz libiconv-1.13.1.tar.gz 
cd libiconv-1.13.1 
./configure --prefix=/usr/local/Cellar/libiconv/1.13.1 
make 
sudo make install 
sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2 
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.8.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.8.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib