Car*_*ham 12 macos homebrew rubygems libxml2 libxml-ruby
我正在尝试安装libxml-ruby.我安装了libxml2,libxslt和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)
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
sca*_*er2 13
升级到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
Run Code Online (Sandbox Code Playgroud)
在我的例子中,我安装2.9.0了libxml-ruby gem的版本.更改版本字符串以满足您的需要.如果可用,请检查Gemfile.lock以确定libxml-ruby需要安装哪个版本的Bundler.
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
Run Code Online (Sandbox Code Playgroud)
自酿:
libxml2仅限于桶,这意味着它没有符号链接到/ usr / local,因为macOS已经提供了该软件,并且并行安装另一个版本可能会引起各种麻烦。
因此,我们需要直接设置libxml路径
brew install libxml2
gem install libxml-ruby \
-- \
--with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config"
Run Code Online (Sandbox Code Playgroud)
聚苯乙烯
如果您在最新的红宝石上例外:
只是忽略它。gem已成功安装。仅Rdoc文档生成失败。
The internal error was:
(NoMethodError) undefined method `[]' for nil:NilClass
ERROR: While executing gem ... (NoMethodError)
undefined method `[]' for nil:NilClass
Run Code Online (Sandbox Code Playgroud)
高级别问题显示在这里:
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no
Run Code Online (Sandbox Code Playgroud)
基本上,安装程序会告诉您找不到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
Run Code Online (Sandbox Code Playgroud)