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

In Rails 3, I noticed that every time I call the framework, be it rake , rails server or something else, I get the following warning:

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

A Google search provides several blog posts, all of which suggest rebuilding Nokogiri using explicit lib and include libraries. For example:

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

But this did not solve the problem for me.

Entering nokogiri -v gives me the following:

 --- 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 fine and Nokogiri is loading the correct library versions. Why is Rails complaining?

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

+10
ruby ruby-on-rails nokogiri
Jan 28 '11 at 18:26
source share
2 answers

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

I tried rebuilding RMagick against libxml 2.7.7 as follows:

 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 these flags. It was again built using 2.7.3. (If anyone knows how to create RMagick for a specific version of libxml, please share your knowledge.)

Ultimately, I found a solution halfway. I decided that if I could not resolve the version conflict between the two gems, I would at least approve Nokogiri, which uses the newer version of libxml. To do this, I found out which gems in my Gemfile used Nokogiri and placed them first.

So, when I once had this:

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

Now I have this:

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

Now the warning has disappeared, and RMagick has not yet complained. Disclaimer: I do not use SVG in my applications, so I have not confirmed that RMagick is fully compatible with libxml 2.7.7.

+14
Jan 28 '11 at 18:26
source share

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

+6
Jun 28 2018-12-12T00:
source share



All Articles