如何在自定义的Rails引擎gem中加载正确版本的动态库和gem(libxml,Nokogiri)? [英] How to load correct version of dynamic libraries and gems (libxml, Nokogiri) within a custom Rails engine gem?

查看:217
本文介绍了如何在自定义的Rails引擎gem中加载正确版本的动态库和gem(libxml,Nokogiri)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建使用Nokogiri gem的Rails引擎,但是我在MacOS 10.7和10.8中的开发设置遇到了麻烦:

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:

为了使Nokogiri在我的设置中正常工作,我使用以下命令更新了libxml和libxslt库:

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

如果我在常规" rails应用程序中使用它,则Nokogiri可以正常工作(将其包含在Gemfile中,运行捆绑安装).

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

当我尝试从正在构建的Rails Engine中使用Nokogiri并将其从我的应用程序中用作宝石时,就会出现问题.

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.

在gemspec中:

s.add_dependency 'nokogiri' # XML parsing

我还在Gem的Gemfile顶部尝试了以下操作:

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

gem 'nokogiri'

当我启动一个使用Rails Engine gem的应用程序时,会收到以下警告:

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

如何配置gem和/或bundler和/或Rails以使用Nokogiri和libxml和libxslt的正确版本?

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

另外,这是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

推荐答案

将Rails Engine gem放置在应用程序的Gemfile顶部.然后,在Rails Engine的gemspec和Gemfile中,确保在使用libxml的其他gem(例如pg)之前,您拥有nokogori.

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

这篇关于如何在自定义的Rails引擎gem中加载正确版本的动态库和gem(libxml,Nokogiri)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆