15

我正在尝试安装libxml-ruby. 我已经安装了libxml2libxslt并且coreutils

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

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
4

7 回答 7

18

在我使用 brew 安装 libxml2 后,我遇到了类似的问题

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

于 2017-10-16T21:21:29.490 回答
16

升级到 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

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

于 2018-11-17T16:05:54.710 回答
12

自制:

libxml2 是仅限于桶的,这意味着它没有符号链接到 /usr/local,因为 macOS 已经提供了这个软件,并且并行安装另一个版本可能会导致各种麻烦。

所以,我们需要直接设置libxml路径

brew install libxml2

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

附言

如果您在最新的红宝石上遇到异常:

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

The internal error was:

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

ERROR:  While executing gem ... (NoMethodError)
    undefined method `[]' for nil:NilClass
于 2019-03-14T12:45:19.433 回答
7

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
于 2019-03-06T16:36:34.310 回答
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安装位置。根据这个答案,我猜你的问题是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
于 2016-06-30T23:11:10.223 回答
4

我也曾经brew安装过,libxml2但需要以下选项:

brew install libxml2 --with-xml2-config
gem install libxml-ruby -- --with-xml2-config=/usr/local/homebrew/opt/libxml2/bin/xml2-config
于 2018-09-11T20:54:41.743 回答
1

一种解决方案是:

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

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

于 2019-04-25T16:18:07.510 回答