使用其他include和lib路径安装gem

时间:2014-05-09 07:35:15

标签: ruby gem rubygems nokogiri libxml2

我正在尝试在Mac OS X 10.9.2上构建和安装nokogiri Rubygem,这需要libxml2。传递--with-xml2-lib--with-xml2-include选项似乎没有生效

$ gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 --with-xml2-lib=/usr/local/lib 

设置LDFLAGS和CPPFLAGS也不起作用(使用Homebrew版本的libxml2而不是Xcode)

$ LDFLAGS="-L/usr/local/opt/libxslt/lib -L/usr/local/opt/libxml2/lib" CPPFLAGS="-I/usr/local/opt/libxslt/include -I/usr/local/opt/libxml2/include" gem install -r nokogiri

错误输出始终相同

checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for iconv_open() in iconv.h... yes
checking for xmlParseDoc() in -lxml2... no
-----
libxml2 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
    --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=/usr/local/Cellar/ruby/2.1.1_1/bin/ruby
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --with-iconv-dir
    --without-iconv-dir
    --with-iconv-include
    --without-iconv-include=${iconv-dir}/include
    --with-iconv-lib
    --without-iconv-lib=${iconv-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include=${xml2-dir}/include
    --with-xml2-lib=${xml2-dir}/lib
    --with-xslt-dir
    --with-xslt-include
    --without-xslt-include=${xslt-dir}/include
    --with-xslt-lib
    --without-xslt-lib=${xslt-dir}/lib
    --with-libxslt-config
    --without-libxslt-config
    --with-pkg-config
    --without-pkg-config
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-libiconv-config
    --without-libiconv-config
    --with-xml2lib
    --without-xml2lib

extconf failed, exit code 1

3 个答案:

答案 0 :(得分:5)

使用Homebrew安装gem首先依赖的库,然后在实际安装gem之前设置NOKOGIRI_USE_SYSTEM_LIBRARIES=1对我有用。

汇总:

  • 如果以前安装过,请卸载gem:
    $ gem uninstall nokogiri

  • 使用Homebrew安装libxml2libxsltlibiconv
    $ brew install libxml2 libxslt libiconv

  • 安装gem,指定要链接的库的路径:
    $ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"

答案 1 :(得分:3)

我遇到了同样的问题,但以下内容对我有用:

gem install -- --with-opt-include=/usr/local/opt/libxml2/include/libxml2

答案 2 :(得分:0)

您是否阅读过:https://github.com/sparklemotion/nokogiri/wiki/What-to-do-if-libxml2-is-being-a-jerk

这通常有帮助。其他类似的问题也有帮助。

类似的问题:

Getting nokogiri to use a newer version of libxml2

相关问题