【问题标题】:Why does installing Nokogiri on Mac OS fail with libiconv is missing?为什么在 Mac OS 上安装 Nokogiri 失败并缺少 libiconv?
【发布时间】:2011-07-28 13:58:07
【问题描述】:

我一直在尝试在 Mac OS 10.9.3 上安装 Nokogiri,无论我尝试什么,安装最终都会失败并显示以下错误消息:

$ sudo gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28 --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib
Building native extensions with: '--with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28 --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib'
This could take a while...
Building nokogiri using packaged libraries.
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28 --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib
Building nokogiri using packaged libraries.
checking for iconv.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... no
checking for libiconv_open() in iconv.h... no
checking for libiconv_open() in -liconv... no
-----
libiconv is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    --help
    --clean
    --use-system-libraries
    --enable-static
    --disable-static
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --enable-cross-build
    --disable-cross-build


Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.2.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.2.1/ext/nokogiri/gem_make.out

在网上找到很多帮助后,包括使用 brew 构建和安装 libxml2 和 libxslt 以及从源代码构建 libiconv(如“Installing Nokogiri”中所述),错误仍然存​​在。

在尝试运行 Nokogiri 的安装时,似乎发现 libxml2 和 libxslt 正常,但 libiconv 不正常。

任何对这些事情有更深入了解的人都知道如何安装 Nokogiri 吗?

【问题讨论】:

  • 您没有显示您尝试使用的确切命令,因此我们将在黑暗中拍摄试图回答。我总是使用gem install nokogiri,但后来我使用 RVM 来管理我的 Mac OS Ruby 安装。 libxml 和 libxslt 与 iconv 无关,所以我建议您在他们的支持论坛Nokogiri-talk 上提问。我不记得在安装 Nokogiri 时遇到任何 iconv 问题,而且我在一堆机器上都有它。
  • 我在 github 上开了一张票:github.com/tenderlove/nokogiri/issues/442 其中包含更多信息。
  • 这是解决 OSX El Capitan 上相同问题的链接,estebantorr.es/blog/2015/10/02/Nokogiri-in-El-Capitan
  • sudo gem install nokogiri”。不要使用sudo 安装gem 或修改默认的Ruby。而是使用 rbenv 或 RVM 来管理单独的 Ruby。这在 Stack Overflow 上已多次提及。
  • 在安装 nokogiri 之前您是否尝试过uninstalling xz

标签: ruby macos nokogiri libxml2 libiconv


【解决方案1】:

假设您使用 MacPorts 安装了 libxml2 和 libxslt,那么由于调用 have_func('iconv_open', 'iconv.h') 使用的包含路径和链接路径的顺序不匹配,您可能仍然会收到此错误

简单(补丁)解决方案:删除 /usr/local/lib 中的 libiconv.*

【讨论】:

  • 我已经用 MacPorts 安装了 libxml2 和 libxslt,但是 /usr/local/lib 中没有 libiconv.* 文件
【解决方案2】:

查看 mkmf 文件,似乎 nokogiri(或 gem,我不知道)尝试在 /op/local/ 中查找依赖项。对我来说,这不是搜索它们的正确途径。

强制 nokogiri 在正确的位置找到库(我使用自制软件)对我有用:

$ gem install nokogiri -- --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-xml2-dir=/usr/local/Cellar/libxml2/2.7.8/

也许在 nokogiri 中有一些需要修复的东西......

HTH,

【讨论】:

    【解决方案3】:

    查看 gem 构建目录中的 mkmf.log 文件(例如 /Library/Ruby/Gems/1.8/gems/nokogiri-1.4.4/ext/nokogiri/mkmf.log)。那有更多的信息。就我而言,当我点击它时,Nokogiri 专门将 /opt/local/lib 添加到库搜索路径中,而 GNU Backgammon 在那里安装了不兼容的 libiconv。

    【讨论】:

      猜你喜欢
      • 2014-09-02
      • 2013-01-06
      • 1970-01-01
      • 2015-10-24
      • 2019-12-28
      • 1970-01-01
      • 2022-06-29
      • 2019-05-07
      • 2017-02-23
      相关资源
      最近更新 更多