Mac用户并获得警告:Nokogiri是针对LibXML版本2.7.8构建的,但动态加载了2.7.3

Bin*_*gic 82 ruby macos libxml2 nokogiri

我做了各种各样的研究,尝试了很多不同的东西.我知道这个问题已被多次回答,但没有一个建议的解决方案对我有用.

升级到Lion后,我在Ruby中遇到了分段错误.我相当自信是Nokogiri.所以我通过Homebrew安装了libxml2.我跑brew link libxml2.然后我使用该版本的库重新安装了Nokogiri.

证明:

$ nokogiri -v
# Nokogiri (1.5.0)
---
warnings: []
nokogiri: 1.5.0
ruby:
  version: 1.9.2
  platform: x86_64-darwin11.0.0
  description: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.0]
  engine: ruby
libxml:
  binding: extension
  compiled: 2.7.8
  loaded: 2.7.8
Run Code Online (Sandbox Code Playgroud)

我已经将Nokogiri包含在我的gemfile的顶部,我也在我的环境文件中需要它.我不知道为什么我仍然会收到警告.

任何建议或想法,以确保它正在加载正确的版本libxml2?

ind*_*ect 96

如果您安装了Nokogiri gem install nokogiri,则可以通过运行gem pristine nokogiri重新编译gem的C扩展来解决此警告.

如果您安装了Nokogiri bundle install,则可以通过bundle exec gem pristine nokogiri在Bundler安装它的任何地方运行重新编译gem的C扩展来解决此警告.

  • 这对我有用,接受的答案没有. (12认同)
  • 非常好,谢谢.`捆绑exec gem pristine nokogiri`钉它. (5认同)

Mic*_*are 58

要解决此问题,如果您使用自制程序和捆绑程序,请添加gem 'nokogiri' 的顶部Gemfile,然后运行以下命令:

gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 --with-xml2-config
brew install libxslt
bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
bundle install
Run Code Online (Sandbox Code Playgroud)

如果您不使用bundler,请改为运行以下命令:

gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 --with-xml2-config
brew install libxslt
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
Run Code Online (Sandbox Code Playgroud)

在您的应用程序中,您应该首先要求nokogiri,强制应用程序加载动态libxml2库,而不是由未能指定要加载哪个库的gem加载的旧系统版本的libxml2.

  • 需要强调的是,最后一句很重要:**首先要求nokogiri**通过在轨道之前将nokogiri放入Gemfile中来做到这一点. (7认同)
  • 对于那些复制粘贴这个答案,最新版本的libxml2是2.9.0 - 请务必在复制粘贴时编辑它! (5认同)
  • 有没有理由你不包括`brew uninstall libxslt`? (4认同)

Ken*_*ton 39

我只是花了大部分时间来完成这个警告.此修复适用于使用Mac OS Lion的用户.上面的修复使用

bundle config build.nokogiri --with-xml2-include=/opt/local/include/libxml2 --with-xml2-lib=/opt/local/lib --with-xslt-dir=/opt/local
Run Code Online (Sandbox Code Playgroud)

适用于通过MacPorts安装libxml2的Snow Leopard.

使用Lion,libxml2作为引导过程的一部分加载.无论libxml2 Nokogiri指向哪个,libxml2的Lion系统默认库都将在运行时使用.Lion使用libxml2.2.7.3 /usr(not not /usr/local).

正如许多其他地方所提到的,人们可以忽略警告.如果像我一样,警告会让你发疯,你可以这样做:

bundle config build.nokogiri --with-xml2-dir=/usr --with-xslt-dir=/opt/local --with-iconv-dir=/opt/local
Run Code Online (Sandbox Code Playgroud)

有趣的是,如果您nokogiri -v在命令行键入,您将收到相反的警告:

WARNING: Nokogiri was built against LibXML version 2.7.3, but has dynamically loaded 2.7.8
Run Code Online (Sandbox Code Playgroud)

这表明如何加载libxml2,Ruby和Rails使用系统加载的libxml2和命令行使用来自环境路径的libxml2.无论如何,这为我沉默了错误.

我会再说一遍 - 这只适用于狮子座.之前的修复程序适用于Snow Leopard.

这是答案的结束.别在这里读.


好的,你没有停止阅读......好吧......

不建议!!!!!!

你被警告了.您可以通过禁用找到的libxml2来验证Mac OSX是否正在其引导程序中加载libxml2库/usr/lib.这样做的复制所有版本的libxml2*.dyliblibxml2*.dylib.old(我的机器上,这是libxml2.2.7.3,libxml2.2libxml2).

完成此操作后,运行Nokogiri不会产生任何错误.这是因为它无法找到加载libxml2和现在将遵循环境路径,辗转libxml2.2.7.8/opt/local.

但是你将无法复制旧的libxml文件.这是因为操作系统需要在引导程序中加载的libxml2.

关闭电源并重新打开电源会使机器变硬.登录屏幕将挂起并挂起并挂起.在单用户模式下关闭电源并再次打开电源(保持Command- S重新启动时).你可以看到引导程序发生.低,看,它抛出一个错误,它无法加载libxml2然后停止工作.

关闭电源并再次打开电源.这次启动进入恢复模式(按住Command- R或按住Option然后选择恢复磁盘).在恢复模式下打开终端(utilities/terminal).挂载/usr/libHD(尝试/Volumes/Macintosh\ HD/usr/lib)并复制libxml2文件.重启,一切都会好的.

  • 我在这个解决方案上使用了一个变体(我的动态加载版本是2.9.0):`bundle config build.nokogiri --with-xml2-include =/usr/local/Cellar/libxml2/2.9.0/include/libxml2/` (2认同)

nka*_*dwa 27

这些都不适合我.

我使用brew安装了更高版本(2.7.8)的libxml2.这导致nokogiri编译反对它和后来的问题.解决方案,删除它,然后构建,然后根据需要安装.

这是有效的:

  • brew uninstall libxml2 (如果以前安装过)
  • gem uninstall nokogiri
  • gem install nokogiri
  • brew install libxml2 (可选的)

  • 这在OS X 10.8.2上使用libxml 2.7.8/2.8.0修复了它.只是删除nokogiri宝石并重新安装它并没有解决它,但事先做了"brew uninstall libxml2".谢谢! (3认同)

IAm*_*NaN 15

更新到Mountain Lion后的解决方案(对我来说)更为简单:

gem uninstall nokogiri
# (and ignore the warnings about dependencies)
gem install nokogiri
Run Code Online (Sandbox Code Playgroud)

  • 感谢您的反馈,Old Pro.我鼓励您考虑重新阅读SO特权问答."每当你遇到一个令人震惊的草率,不费吹灰之力的帖子,或者一个明显且可能是危险错误的答案时,请使用你的downvotes." 这个答案明显适用于包括OP在内的几个人,因此我认为它不值得进行暗示. (4认同)

Sha*_*aun 9

根据上面patrickmcgraw的评论,简单地将nokogiri作为我的Gemfile中的第一个条目为我工作.我把它作为一个单独的答案,因为最初的评论已被埋没.

source 'http://rubygems.org'
gem 'nokogiri'
gem 'rails', '3.0.20'
etc...
Run Code Online (Sandbox Code Playgroud)