WARNING: Nokogiri was built against LibXML version

2019-01-17 06:40发布

问题:

I can’t work out why I’m getting this error from Nokogiri when I start up Rails. From the little I know, it seems like something else is causing an older version of libxml2 to be loaded, which Nokogiri then ends up using, rather than the version it was compiled against.

What do I need to do to get this working without the warning (and with the right libxml2)?

I’m running this on a Macbook with OS X 10.5.8:

$ rake db:create
(in /Users/gareth/Sites/Rails3/ngtest)
WARNING: Nokogiri was built against LibXML version 2.7.7, but has dynamically loaded 2.6.16
HI.  You're using libxml2 version 2.6.16 which is over 4 years old and has
plenty of bugs.  We suggest that for maximum HTML/XML parsing pleasure, you
upgrade your version of libxml2 and re-install nokogiri.  If you like using
libxml2 version 2.6.16, but don't like this warning, please define the constant
I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2 before requring nokogiri.

ngtest_test already exists
ngtest_development already exists

$ DYLD_PRINT_LIBRARIES=1 rake db:create
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/bin/ruby
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/libruby.1.9.1.dylib
dyld: loaded: /usr/lib/libSystem.B.dylib
dyld: loaded: /usr/lib/libobjc.A.dylib
dyld: loaded: /usr/lib/libgcc_s.1.dylib
dyld: loaded: /usr/lib/system/libmathCommon.A.dylib
dyld: loaded: /usr/lib/libauto.dylib
dyld: loaded: /usr/lib/libstdc++.6.dylib
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/enc/encdb.bundle
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/enc/trans/transdb.bundle
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/etc.bundle
(in /Users/gareth/Sites/Rails3/ngtest)
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/stringio.bundle
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/syck.bundle
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/digest/sha1.bundle
dyld: loaded: /usr/lib/libcrypto.0.9.7.dylib
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/digest.bundle
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/enc/iso_8859_1.bundle
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/zlib.bundle
dyld: loaded: /usr/lib/libz.1.dylib
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/strscan.bundle
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/bigdecimal.bundle
dyld: loaded: /Users/gareth/.rvm/gems/ruby-1.9.2-p136/gems/mysql-2.8.1/lib/mysql_api.bundle
dyld: loaded: /usr/local/Cellar/mysql/5.1.54/lib/mysql/libmysqlclient.16.dylib
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/openssl.bundle
dyld: loaded: /usr/lib/libssl.0.9.7.dylib
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/fcntl.bundle
dyld: loaded: /Users/gareth/.rvm/gems/ruby-1.9.2-p136/gems/eventmachine-0.12.10/lib/rubyeventmachine.bundle
dyld: loaded: /Users/gareth/.rvm/gems/ruby-1.9.2-p136/gems/thin-1.2.7/lib/thin_parser.bundle
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/digest/md5.bundle
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/iconv.bundle
dyld: loaded: /usr/lib/libiconv.2.dylib
dyld: loaded: /Users/gareth/.rvm/gems/ruby-1.9.2-p136/gems/json-1.4.6/ext/json/ext/json/ext/parser.bundle
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/enc/utf_16be.bundle
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/enc/utf_16le.bundle
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/enc/utf_32be.bundle
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/enc/utf_32le.bundle
dyld: loaded: /Users/gareth/.rvm/gems/ruby-1.9.2-p136/gems/json-1.4.6/ext/json/ext/json/ext/generator.bundle
dyld: loaded: /Users/gareth/.rvm/gems/ruby-1.9.2-p136/gems/rpeg-markdown-1.4.6/lib/peg_markdown.bundle
dyld: loaded: /usr/local/Cellar/glib/2.24.2/lib/libglib-2.0.0.dylib
dyld: loaded: /usr/local/Cellar/gettext/0.17/lib/libintl.8.dylib
dyld: loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon
dyld: loaded: /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices
dyld: loaded: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
dyld: loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/CarbonSound.framework/Versions/A/CarbonSound
dyld: loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/CommonPanels.framework/Versions/A/CommonPanels
dyld: loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/Help.framework/Versions/A/Help
dyld: loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox
dyld: loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HTMLRendering.framework/Versions/A/HTMLRendering
dyld: loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/ImageCapture.framework/Versions/A/ImageCapture
dyld: loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/Ink.framework/Versions/A/Ink
dyld: loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/NavigationServices.framework/Versions/A/NavigationServices
dyld: loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/OpenScripting.framework/Versions/A/OpenScripting
dyld: loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/Print.framework/Versions/A/Print
dyld: loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/SecurityHI.framework/Versions/A/SecurityHI
dyld: loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/SpeechRecognition.framework/Versions/A/SpeechRecognition
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices
dyld: loaded: /System/Library/Frameworks/CoreAudio.framework/Versions/A/CoreAudio
dyld: loaded: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/CarbonCore
dyld: loaded: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CFNetwork.framework/Versions/A/CFNetwork
dyld: loaded: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Metadata
dyld: loaded: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Versions/A/OSServices
dyld: loaded: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/SearchKit.framework/Versions/A/SearchKit
dyld: loaded: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/AE
dyld: loaded: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/LaunchServices
dyld: loaded: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/DictionaryServices.framework/Versions/A/DictionaryServices
dyld: loaded: /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
dyld: loaded: /usr/lib/libicucore.A.dylib
dyld: loaded: /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration
dyld: loaded: /usr/lib/libbsm.dylib
dyld: loaded: /System/Library/Frameworks/Security.framework/Versions/A/Security
dyld: loaded: /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration
dyld: loaded: /usr/lib/libsqlite3.0.dylib
dyld: loaded: /usr/lib/libresolv.9.dylib
dyld: loaded: /usr/lib/libxml2.2.dylib
dyld: loaded: /usr/lib/libxslt.1.dylib
dyld: loaded: /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/ATS
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ColorSync.framework/Versions/A/ColorSync
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreText.framework/Versions/A/CoreText
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/HIServices
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/ImageIO
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/LangAnalysis.framework/Versions/A/LangAnalysis
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/PrintCore
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/QD.framework/Versions/A/QD
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/SpeechSynthesis.framework/Versions/A/SpeechSynthesis
dyld: loaded: /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate
dyld: loaded: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vImage.framework/Versions/A/vImage
dyld: loaded: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/vecLib
dyld: loaded: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvMisc.dylib
dyld: loaded: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvDSP.dylib
dyld: loaded: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
dyld: loaded: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources/libJPEG.dylib
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources/libTIFF.dylib
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources/libGIF.dylib
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources/libPng.dylib
dyld: loaded: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources/libRadiance.dylib
dyld: loaded: /usr/lib/libcups.2.dylib
dyld: loaded: /System/Library/Frameworks/Kerberos.framework/Versions/A/Kerberos
dyld: loaded: /System/Library/PrivateFrameworks/CoreUI.framework/Versions/A/CoreUI
dyld: loaded: /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore
dyld: loaded: /System/Library/PrivateFrameworks/DesktopServicesPriv.framework/Versions/A/DesktopServicesPriv
dyld: loaded: /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL
dyld: loaded: /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLImage.dylib
dyld: loaded: /usr/lib/libffi.dylib
dyld: loaded: /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo
dyld: loaded: /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib
dyld: loaded: /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib
dyld: loaded: /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLProgrammability.dylib
dyld: loaded: /System/Library/PrivateFrameworks/InstallServer.framework/Versions/A/InstallServer
dyld: loaded: /Users/gareth/.rvm/gems/ruby-1.9.2-p136/gems/nokogiri-1.4.4/lib/nokogiri/nokogiri.bundle
dyld: loaded: /usr/local/Cellar/libxslt/1.1.26/lib/libexslt.0.dylib
dyld: loaded: /usr/local/Cellar/libxslt/1.1.26/lib/libxslt.1.dylib
dyld: loaded: /usr/local/Cellar/libxml2/2.7.7/lib/libxml2.2.dylib
WARNING: Nokogiri was built against LibXML version 2.7.7, but has dynamically loaded 2.6.16
HI.  You're using libxml2 version 2.6.16 which is over 4 years old and has
plenty of bugs.  We suggest that for maximum HTML/XML parsing pleasure, you
upgrade your version of libxml2 and re-install nokogiri.  If you like using
libxml2 version 2.6.16, but don't like this warning, please define the constant
I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2 before requring nokogiri.

dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/racc/cparse.bundle
dyld: loaded: /Users/gareth/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/i386-darwin9.8.0/socket.bundle
ngtest_test already exists
ngtest_development already exists

$ nokogiri -v
--- 
warnings: []

nokogiri: 1.4.4
ruby: 
  version: 1.9.2
  platform: i386-darwin9.8.0
  engine: ruby
libxml: 
  binding: extension
  compiled: 2.7.7
  loaded: 2.7.7

回答1:

In the end I had to install the gem against the specific versions of xml2 and xslt I have installed:

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.7/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.7/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26
#. scrollbar line, so the code can be seen

The problem was most likely bad library management, switching between package managers without being tidy enough about it.



回答2:

Fix for Nokogiri w. libxml2 2.7.8 loading libxml2 2.7.3

Wanted to add to the above answers: If you dont have libxml2 in the Cellar directory on OSX, you can install it to this using homebrew, as explained on Nokogiri's homepage (homebrew 0.8 or higher, test with brew -v):

brew install libxml2 libxslt
brew link libxml2 libxslt
gem install nokogiri -- --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include


回答3:

I had a different warning:

WARNING: Nokogiri was built against LibXML version 2.7.7, but has dynamically loaded 2.7.8

rebuilt the gem with the newer library to get rid of the warning:

gem install --no-rdoc --no-ri nokogiri -- --with-xml2-include=/opt/local/include/libxml2 --with-xml2-lib=/opt/local/lib


回答4:

The accepted solution didn't work for me, but this did:

gem install --no-rdoc --no-ri nokogiri -- --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib

This compiles against the MacOS system library. It's possible Macports (which I prefer to brew) is not set up properly on my machine, though.



回答5:

Nokogiri was built correctly, but another gem was required first and loaded the old libxml2 library.

In your app, you should require nokogiri first, to force the app to load the dynamic libxml2 library instead of the older system version of libxml2 loaded by gems that failed to specify which library to load.



回答6:

Per Stella Miranda, I followed the steps to resolve my own nokogiri issue on Mountain Lion:

  1. gem uninstall nokogiri
  2. gem install nokogiri

No more nokogiri warnings!



回答7:

Ensure it's not just a ruby compilation issue. This just came up on OSX Mountain Lion, as the system libxml was bumped, but the ruby was compiled on the previous libxml. It can be solved by uninstalling and reinstalling ruby.

My answer on another thread for reference: https://stackoverflow.com/a/11714789/1561677



回答8:

I used to have an issue like that, do you really need two version of libxml on your system? Otherwise, uninstall all the older version of libxml and just in case force the reinstallation of nokogiri.



回答9:

I was having the same problem. All I did was add a line in my Gemfile to explicitly require the most recent version of nokogiri (as of 3/17/2013, 1.5.6), then I did a bundle update nokogiri, and it fixed the problem.