Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

ruby - How to load correct version of dynamic libraries and gems (libxml, Nokogiri) within a custom Rails engine gem?

I am building a rails engine that uses the Nokogiri gem and I'm having trouble with my development setup in MacOS 10.7 and 10.8:

In order for Nokogiri to work properly in my setup, I updated the libxml and libxslt libraries with:

brew update
brew install libxslt
brew upgrade libxml2
gem uninstall nokogiri
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28

And Nokogiri works properly if I use it in a "regular" rails app (Include it in the Gemfile, run bundle install).

The problem appears when I try to use Nokogiri from a Rails Engine that I'm building and using from my app as a gem.

In gemspec:

s.add_dependency 'nokogiri' # XML parsing

I also tried the following in the top of the Gem's Gemfile:

gem 'nokogiri'

When I start an app that uses my Rails Engine gem, I get the following warning:

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

How do I configure the gem and/or bundler and/or Rails to use the correct version of Nokogiri and libxml and libxslt ?

Also, here's the output of nokogiri -v

# Nokogiri (1.5.9)
    ---
    warnings: []
    nokogiri: 1.5.9
    ruby:
      version: 1.9.3
      platform: x86_64-darwin12.3.0
      description: ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.3.0]
      engine: ruby
    libxml:
      binding: extension
      compiled: 2.9.0
      loaded: 2.9.0
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Put you Rails Engine gem in the top of the app's Gemfile. Then, in the gemspec and Gemfile of the Rails Engine, make sure that you have nokogori before other gems that use libxml (like pg).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...