How to load correct version of dynamic libraries a

2020-02-13 03:55发布

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条回答
Melony?
2楼-- · 2020-02-13 04:04

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

查看更多
登录 后发表回答