【问题标题】:Error building gems in Mountain Lion在 Mountain Lion 中构建宝石时出错
【发布时间】:2012-12-14 21:28:35
【问题描述】:

我刚买了一台新的 MacBook Pro(显然是带 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 gem,但是当我尝试安装 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.

好像我有开发工具,所以我无法弄清楚问题所在。有什么想法吗?

【问题讨论】:

    标签: ruby macos gem nokogiri


    【解决方案1】:

    我不得不四处看看,但我在 github 上找到了解决方案: https://github.com/sparklemotion/nokogiri/issues/442#issuecomment-7978408

    libxml2 丢失。

    我发现需要一个额外的步骤来解决 Homebrew 的上述问题 Mac OS X 10.8 Mountain Lion 上的 0.9 即创建“/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
    

    【讨论】:

      【解决方案2】:

      在这种情况下,您需要 libxml 的开发头文件,这些头文件未作为编译器工具的一部分提供。通常您需要安装HomebrewMacPorts 之一来帮助安装这些依赖项。

      如果您不熟悉,这里的提示有点难以在噪音中发现,但是:

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

      .h 文件随开发包一起提供,是针对这些库编译扩展所必需的。

      【讨论】:

      • 谢谢。我在 Nokogiri 网站上找到了使用 Homebrew 0.9 进行安装的说明,但仍然出现相同的错误。也许 Homebrew 0.9.3 打破了其他东西。接下来我会试试 MacPorts。
      猜你喜欢
      • 2012-08-15
      • 2011-02-03
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-06
      相关资源
      最近更新 更多