Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 为什么在Mac OS上安装Nokogiri失败,而libiconv丢失?_Ruby_Macos_Nokogiri_Libxml2_Libiconv - Fatal编程技术网

Ruby 为什么在Mac OS上安装Nokogiri失败,而libiconv丢失?

Ruby 为什么在Mac OS上安装Nokogiri失败,而libiconv丢失?,ruby,macos,nokogiri,libxml2,libiconv,Ruby,Macos,Nokogiri,Libxml2,Libiconv,我一直在尝试在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/

我一直在尝试在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(如“”中所述)之后,错误仍然存在

在尝试运行Nokogiri的安装时,libxml2和libxslt似乎还可以,但libiconv却不行

xcode-select --install

任何对这些东西有更好了解的人都知道如何安装Nokogiri?

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

查看mkmf文件,可能是Nokogiri(或gem,我不知道)试图在/op/local/中查找依赖项。对我来说,这不是寻找他们的正确途径

强迫nokogiri在正确的位置找到LIB(我使用自制)对我来说是个好办法:

$ gem install nokogiri -- --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-xml2-dir=/usr/local/Cellar/libxml2/2.7.8/
也许在nokogiri有一些事情需要解决


嗯,我也有同样的问题。不幸的是,“”没有涵盖Iconv问题。下面是我如何解决这个问题的

首先安装,它将使您的生活更轻松。如果您已经安装了它,请务必通过如下方式更新以获取最新的公式:

brew update
注意:在OSX 10.9+中,您可能需要安装xCode命令工具,以便安装libiconv

xcode-select --install
然后安装更新版本的libiconv

brew install libiconv
然后安装你的gem

gem install nokogiri -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14

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


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

在遵循指南之后,我仍然有这个问题。我就是这样解决的:

首先,我使用自制软件安装了iconv: brew安装iconv

然后我卸载了ruby,幸运的是使用rvm很容易:

rvm uninstall 1.9.2        
然后,我必须使用以下选项重新安装ruby:

CC=gcc-4.2 rvm install 1.9.2-p290 --with-iconv-dir=/usr/local/Cellar/libiconv/1.13.1
然后,我使用新的ruby版本创建了一个gemset:

rvm use 1.9.2@coolproject
然后我终于可以像这样安装nokogiri:

gem install nokogiri -v=1.4.4 -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26
Installing nokogiri (1.6.2.1) Building nokogiri using packaged libraries.

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-2.0.0-p0/bin/ruby extconf.rb
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 ***

我尝试了很多东西,但都不管用。后来我终于找到了答案,它救了我一天

我终于解决了这个问题。以上的解决方案都不能完全解决我的问题

我在OSX Lion 10.7.2上尝试
gem安装nokogiri
时遇到了这个错误。首先,这个错误通过说libiconv丢失来掩盖真正的问题,因为即使nokogiri找不到libxslt或libxml2,您也会得到同样的错误,在我的例子中,它找不到

因此,我按照上的说明,在自制部分(稍作修改以说明libxml2的最新版本):

在这一点上,我按照nokogiri网站上的指示进行了尝试

gem install nokogiri -- --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26
但是,这仍然失败,因为在从源代码构建libxslt时,它会将
/include
文件夹安装在一个时髦的地方。因此,您需要分别指定
lib
include
文件夹,如下所示:

gem install nokogiri -- --with-xslt-lib=/usr/local/Cellar/libxslt/1.1.26/lib --with-xslt-include=/usr/local/Cellar/libxslt/1.1.26/include/libxslt
这仍然不起作用(相同的libiconv错误),因此我尝试指定所有三个必需的库(libxslt、libxml2和libiconv):

现在我犯了一个不同的错误!这仍然是一个错误,但至少是不同的。生成过程失败,原因是:

in /opt/local/lib/libz.1.dylib, file was built for unsupported file format which is not the architecture being linked (x86_64) for architecture x86_64
嗯,什么?在谷歌搜索了很多次之后,我发现了这篇神奇的帖子:

显然OSX Lion附带了一些不好的libz库版本(
libz.dylib、libz.1.dylib、libz.1.2.4.dylib
),需要用Xcode SDK的最新版本替换它们。这篇文章对它的解释比我能读到的要好,因此我可以阅读上面的链接以获得具体的说明

一旦更换了,我就跑了

gem install nokogiri -- --with-xslt-lib=/usr/local/Cellar/libxslt/1.1.26/lib --with-xslt-include=/usr/local/Cellar/libxslt/1.1.26/include/libxslt --with-iconv-dir=/usr/local/Cellar/libiconv/1.14 --with-xml2-dir=/usr/local/Cellar/libxml2/2.7.8
一切都很好。我希望这对其他人有帮助

$ gem install nokogiri -- --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-xml2-dir=/usr/local/Cellar/libxml2/2.7.8/
如上所述,这是用于自制和使用gem安装的解决方案(应用更改取决于您的版本)

但是,如果使用Gemfile和bundle安装,则应在安装之前应用bundle配置,下面是代码

$ bundle config build.nokogiri --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-xml2-dir=/usr/local/Cellar/libxml2/2.7.8/ --with-iconv-dir=/usr/local/Cellar/libiconv/1.14
同样,应用更改取决于您的版本

希望这对你有帮助


信用证:

libiconv已从Homebrew 0.9中删除,现在建议从源代码处编译libiconv,然后在安装nokogiri gem时参考安装。在我的例子中(与scotchi一样),由于/opt/local/lib中的iconv库不兼容,构建失败,请参阅“自制0.9”一节中的Nokogiri安装说明。 默认情况下,Nokogiri构建过程首先查看/opt/local。 要强制它使用不同的安装目录,例如/usr/local,请执行以下操作:

gem install nokogiri -- --with-xml2-lib=/usr/local/lib --with-xml2-include=/usr/local/include/libxml2 --with-xslt-lib=/usr/local/lib --with-xslt-include=/usr/local/include

我在《山狮》上也遇到过类似的麻烦。原来我以前已经通过rvm包安装了libiconv,ruby 1.9.3/Mountain Lion/nokogiri不再需要它


按照的建议,我删除了$rvm_path/usr目录并重建了ruby 1.9.3。此后,安装nokogiri是一个简单的gem安装。请勿干扰brew/macports/手动源代码安装

您需要将自制软件升级到0.9

然后按照以下步骤操作

brew install libxml2 libxslt
brew link libxml2 libxslt
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
tar xvfz libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure --prefix=/usr/local/Cellar/libiconv/1.13.1
make
sudo make install

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

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 --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib
您应该仔细检查文件夹库版本

这建议手动安装libiconv

随后,nokogiri可以安装一些开关,告诉它在哪里可以找到libiconv(参见博客文章)

附带说明:在安装nokogiri之后,我成功地安装了gollum(由于找不到iconv,安装也失败了)。但现在我仍然面临问题,因为当我启动gollum时,Python c
$ gem install iconv # works but it is missing an iconv.so file in ruby 2.0.0-p247

$ ls -1 2.0.0-p0/lib/ruby/gems/2.0.0/gems/iconv-1.0.3/*/*/*.so
2.0.0-p0/lib/ruby/gems/2.0.0/gems/iconv-1.0.3/ext/iconv/iconv.so*
2.0.0-p0/lib/ruby/gems/2.0.0/gems/iconv-1.0.3/lib/iconv/iconv.so*

$ ls -1 2.0.0-p247/lib/ruby/gems/2.0.0/gems/iconv-1.0.3/*/*/*.so
2.0.0-p247/lib/ruby/gems/2.0.0/gems/iconv-1.0.3/ext/iconv/iconv.so*
$ rbenv version
2.0.0-p247 (set by /home/XXX/tmp/.ruby-version)
$ rbenv which gem
/home/XXX/.rbenv/versions/2.0.0-p247/bin/gem
$ gem --version
1.8.25

$ rbenv which pry
/home/XXX/.rbenv/versions/2.0.0-p247/bin/pry
$ pry
[1] pry(main)> require 'iconv'
LoadError: cannot load such file -- iconv/iconv.so
from /home/XXX/.rbenv/versions/2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/custom_require.rb:36:in `require'
$ pushd ~/.rbenv/versions/
$ cp 2.0.0-p247/lib/ruby/gems/2.0.0/gems/iconv-1.0.3/ext/iconv/iconv.so 2.0.0-p247/lib/ruby/gems/2.0.0/gems/iconv-1.0.3/lib/iconv/
$ pry
[1] pry(main)> require 'iconv'
=> true
gem install nokogiri -- --use-system-libraries
bundle config build.nokogiri --use-system-libraries
...
CXX=/usr/local/opt/apple-gcc42/bin/g++-4.2
...
CC=/usr/local/opt/apple-gcc42/bin/gcc-4.2
...
brew update
brew install libxml2 libxslt
brew link libxml2 libxslt
brew link --force libxml2 libxslt
xcode-select --install
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
tar xvfz libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure --prefix=/usr/local/Cellar/libiconv/1.13.1
make
sudo make install
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.8.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.8.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib
xcode-select --install
gem install nokogiri
xcode-select --install
brew unlink libiconv
gem install nokogiri
sudo port uninstall libiconv
gem install nokogiri -- --with-iconv-dir=/opt/local
Installing nokogiri (1.6.2.1) Building nokogiri using packaged libraries.

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-2.0.0-p0/bin/ruby extconf.rb
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 ***
brew unlink gcc-4.2      # you might not need this step
gem uninstall nokogiri
xcode-select --install
gem install nokogiri
xcode-select --install
brew uninstall libiconv
brew install libiconv
gem install nokogiri
╰─% cat .bundle/config           
---
BUNDLE_PATH: vendor/bundle
BUNDLE_DISABLE_SHARED_GEMS: '1'
BUNDLE_JOBS: 4

╰─% which ruby bundle gem
~/.rbenv/shims/ruby
~/.rbenv/shims/bundle
~/.rbenv/shims/gem
sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri -- --use-system-libraries
brew uninstall libiconv
brew uninstall libxml2
brew uninstall libxslt
brew install coreutils
gem install nokogiri