我一直在尝试在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
在遵循web上提供的大量帮助(包括使用brew构建和安装libxml2和libxslt以及从源代码构建libiconv (如“Installing Nokogiri”中所述))之后,错误仍然存在。
当尝试运行Nokogiri的安装时,libxml2和libxslt似乎可以正常运行,但libiconv却不行。
有没有更了解这些的人知道如何安装Nokogiri?
发布于 2011-11-30 08:26:58
我终于能够解决这个问题了。上面的解决方案都不能完全解决我的问题。
当我尝试在OSX Lion 10.7.2上使用gem install nokogiri
时,我得到了这个错误。首先,这个错误通过说libiconv缺失来掩盖真正的问题,因为即使nokogiri找不到libxslt或libxml2,你也会得到同样的错误,在我的例子中,它找不到。
因此,我在http://nokogiri.org/tutorials/installing_nokogiri.html上的Homebrew部分(稍微做了一些修改,以适应更新版本的libxml2)中遵循了说明:
brew install libxml2
brew link libxml2
# install libxslt from source
wget ftp://xmlsoft.org/libxml2/libxslt-1.1.26.tar.gz
tar -zxvf libxslt-1.1.26.tar.gz
cd libxslt-1.1.26
./configure --prefix=/usr/local/Cellar/libxslt/1.1.26 --with-libxml-prefix=/usr/local/Cellar/libxml2/2.7.8
make
sudo make install
在这一点上,我按照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):
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
现在我得到了一个不同的错误!这仍然是一个错误,但至少它是不同的。make进程失败,出现以下错误:
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
呃,怎么了?在谷歌了很多次之后,我偶然发现了这个神奇的帖子:http://www.refresherate.com/2010/01/08/fixing-ld-warning-in-usrlocalliblibz-dylib-file-is-not-of-required-architecture/
显然,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
再一次,一切都很好。我希望这对其他人有帮助。
发布于 2014-11-28 04:22:17
我只是在人群中加入我的声音,但是mkmf.log说了一些关于找不到x86_64架构的符号的事情。我偶然发现了这个解决方案:
sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri -- --use-system-libraries
对于最初的提问者来说,这可能解决不了任何问题,但这可能会对某些人有所帮助。
附注: nokogiri一直是我使用ruby应用程序的最高障碍。每次有人依赖于不同的版本时,我都必须弄清楚如何构建它。我的问题每次都不同。
发布于 2019-09-10 12:00:07
gem install nokogiri -v '1.6.6.2' -- --use-system-libraries --with-xml2-include=$(brew --prefix libxml2)/include/libxml2
这对我在macos上很有效。它也适用于1.6.6.4
版本
https://stackoverflow.com/questions/5528839
复制相似问题