libxml-ruby:无法构建gem原生扩展

时间:2016-06-30 17:02:38

标签: macos rubygems homebrew libxml2 libxml-ruby

我正在尝试安装libxml-ruby。 我安装了libxml2libxsltcoreutils

我还阅读了有关此问题的其他帖子,但没有人为我解决。

brew list libxslt

/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/bin/xslt-config
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/bin/xsltproc
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/include/libexslt/ (3 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/include/libxslt/ (21 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/libexslt.0.dylib
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/libxslt.1.dylib
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/pkgconfig/ (2 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/ (5 other files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/share/aclocal/libxslt.m4
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/share/doc/ (90 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/share/man/ (3 files)

brew list libxml2

/opt/boxen/homebrew/Cellar/libxml2/2.9.4/bin/xml2-config
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/bin/xmlcatalog
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/bin/xmllint
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/include/libxml2/ (47 files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/libxml2.2.dylib
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/cmake/libxml2/libxml2-config.cmake
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/pkgconfig/libxml-2.0.pc
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/ (3 other files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/aclocal/libxml.m4
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/doc/ (153 files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/gtk-doc/ (55 files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/man/ (4 files)

gem install libxml-ruby会产生以下错误:

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

    current directory: /opt/rubies/2.3.0/lib/ruby/gems/2.3.0/gems/libxml-ruby-2.9.0/ext/libxml
/opt/boxen/rbenv/versions/2.3.0/bin/ruby -r ./siteconf20160630-68248-1qaz7dk.rb extconf.rb
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no
*** 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=/opt/boxen/rbenv/versions/2.3.0/bin/$(RUBY_BASE_NAME)
    --with-xml2-config
    --without-xml2-config
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
 extconf failure: need libxml2.

    Install the library or try one of the following options to extconf.rb:

      --with-xml2-config=/path/to/xml2-config
      --with-xml2-dir=/path/to/libxml2
      --with-xml2-lib=/path/to/libxml2/lib
      --with-xml2-include=/path/to/libxml2/include


To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /opt/boxen/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-14/2.3.0-static/libxml-ruby-2.9.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /opt/boxen/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/libxml-ruby-2.9.0 for inspection.
Results logged to /opt/boxen/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-14/2.3.0-static/libxml-ruby-2.9.0/gem_make.out

7 个答案:

答案 0 :(得分:18)

在使用brew安装libxml2

之后,我遇到了类似的问题

Brew链接解决了问题brew link --force libxml2

答案 1 :(得分:10)

升级到macOS Mojave后的寿命。

xcode-select --install
brew install libxml2
brew link --force libxml2
gem install libxml-ruby -v '2.9.0' -- --use-system-libraries=true --with-xml2-include="$(xcrun --show-sdk-path)"/usr/include/libxml2

在我的示例中,我安装了libxml-ruby gem的版本2.9.0。更改版本字符串以适合您的需求。如果可用,请检查Gemfile.lock以确定需要安装哪个版本的libxml-ruby Bundler。

答案 2 :(得分:5)

此处显示了高级别问题:

checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no

基本上,安装程序告诉您找不到libxml/xmlversion.h,但更常见的是,它很可能找不到您的libxml2位置。它告诉你它正在查看哪四个目录,所以第一步是检查这些目录,看看是否有libxml2

假设它不在这四个位置中的任何一个位置,您需要找到它。运行find / -name xmlversion.h(可能需要sudo)以确定安装libxml2的位置。基于this answer我猜你的问题是brew已将其安装到/usr/local/Cellar/libxml2,但您应该确认。获得位置后,您可以手动将gem install命令指向它。这样的事情:(但用实际路径填写path/to

gem install libxml-ruby --with-xml2-dir=/path/to/libxml2 --with-xml2-lib=/path/to/libxml2/lib --with-xml2-include=/path/to/libxml2/include

答案 3 :(得分:5)

自酿:

  

libxml2仅限于小桶,这意味着它没有符号链接到/ usr / local,   因为macOS已经提供了此软件并在其中安装了另一个版本   并行会引起各种各样的麻烦。

因此,我们需要直接设置libxml路径

brew install libxml2

gem install libxml-ruby \
-- \
--with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config"

P.S。

如果您对最近的红宝石有例外情况:

只需忽略它。 gem已成功安装。只是Rdoc文档生成失败。

The internal error was:

        (NoMethodError) undefined method `[]' for nil:NilClass

ERROR:  While executing gem ... (NoMethodError)
    undefined method `[]' for nil:NilClass

答案 4 :(得分:3)

我还使用brew安装libxml2,但需要以下选项:

brew install libxml2 --with-xml2-config
gem install libxml-ruby -- --with-xml2-config=/usr/local/homebrew/opt/libxml2/bin/xml2-config

答案 5 :(得分:1)

macOS始终安装了libmxl2,因此无需首先使用brew之类的实用程序进行安装。然而,标头不在/usr/include/libxml中,而在/usr/include/libxml2/libxml中。

libxml-ruby gem的配置脚本试图通过编译如下代码来检测是否安装了libxml

#include <libxml/xmlversion.h>

但是,当使用Xcode附带的编译器进行编译时,只有以下代码可以工作:

#include <libxml2/libxml/xmlversion.h>

技巧是让配置脚本知道在何处查找标头。在安装了Xcode的macOS系统上,以下操作将起作用:

gem install libxml-ruby -v '3.1.0' -- --with-xml2-include=`xcrun --show-sdk-path`/usr/include/libxml2

答案 6 :(得分:1)

一种解决方案是:

cd /Library/Developer/CommandLineTools/Packages/ $ 
open macOS_SDK_headers_for_macOS_10.14.pkg

强制为macOS 10.14重新安装标头。