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

风流意气都作罢 提交于 2019-11-28 05:45:00

问题


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

回答1:


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).



来源:https://stackoverflow.com/questions/16921700/how-to-load-correct-version-of-dynamic-libraries-and-gems-libxml-nokogiri-wit

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