Nokogiri was built against LibXML version 2.7.7, but has dynamically loaded 2.7.3

丶灬走出姿态 提交于 2019-11-27 04:42:11

问题


In Rails 3, I've noticed that every time I invoke the framework, whether from rake, rails server, or anything else, I get the following warning:

Nokogiri was built against LibXML version 2.7.7, but has dynamically loaded 2.7.3

Searching on Google yields a few blog posts, all of which suggest rebuilding Nokogiri using explicit lib and include paths. For example:

http://mrflip.github.com/2009-08/nokogiri-hates-libxml2-on-osx.html

But, that didn't solve the problem for me.

Typing nokogiri -v gives me this:

--- 
warnings: []

ruby: 
  engine: mri
  version: 1.8.7
  platform: i686-darwin10.4.0
libxml: 
  loaded: 2.7.7
  binding: extension
  compiled: 2.7.7
nokogiri: 1.4.4

Which seems to suggest that my build went OK, and Nokogiri is loading the correct library versions. So why does Rails complain?

I actually found the answer, and I thought I'd share it here. See my answer below.


回答1:


The problem is that other libraries are loading the earlier libxml version. I found this by commenting things out in my Gemfile. Specifically, in my case RMagick was loading libxml 2.7.3. (It uses libxml to read SVG files.)

I tried to rebuild RMagick against libxml 2.7.7 like so:

gem install --no-rdoc --no-ri rmagick -- --with-xml2-include=/opt/local/include/libxml2 --with-xml2-lib=/opt/local/lib --with-xslt-include=/opt/local/libxslt --with-xslt-lib=/opt/local/lib

However, RMagick did not seem to care about those flags. It built using 2.7.3 again. (If anyone knows how to build RMagick against a specific libxml version, please do share your knowledge.)

Ultimately, I did find a halfway-decent solution. I decided that if I couldn't resolve the version conflict between these two gems, I'd at least favor Nokogiri, which uses a newer version of libxml. To do that, I figured out which gems in my Gemfile were using Nokogiri and put them first.

So, whereas I once had this:

gem 'rmagick', :require => 'RMagick'
gem 'sanitize' # Has Nokogiri as dependency

I now have this:

gem 'sanitize' # Has Nokogiri as dependency
gem 'rmagick', :require => 'RMagick'

Now the warning is gone, and RMagick hasn't yet complained. Disclaimer: I don't use SVGs in my apps, so I haven't confirmed that RMagick is fully compatible with libxml 2.7.7.




回答2:


You could also require 'nokogiri' in the first line of your app, before Bundle.require, - then you don't have to figure out what the other dependencies are.



来源:https://stackoverflow.com/questions/4831714/nokogiri-was-built-against-libxml-version-2-7-7-but-has-dynamically-loaded-2-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!