libxml-ruby无法构建原生扩展

时间:2016-05-27 12:57:10

标签: ruby-on-rails ruby osx-elcapitan

我在El Capitan上使用ruby 2.1.10并尝试安装libxml-ruby -v'2.7.0'。

当我跑gem install libxml-ruby -v '2.7.0时,我得到了这个

Building native extensions.  This could take a while...
ERROR:  Error installing libxml-ruby:
    ERROR: Failed to build gem native extension.

    /Users/stuartpearman/.rvm/rubies/ruby-2.1.10/bin/ruby -r ./siteconf20160527-15602-1pq16mj.rb extconf.rb
checking for socket() in -lsocket... no
checking for gethostbyname() in -lnsl... no
checking for atan() in -lm... yes
checking for inflate() in -lz... yes
checking for iconv_open() in -liconv... yes
checking for xmlParseDoc() in -lxml2... yes
checking for libxml/xmlversion.h... yes
checking for rb_io_bufwrite() in ruby/io.h... yes
creating extconf.h
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling libxml.c
compiling ruby_xml.c
ruby_xml.c:612:23: warning: assigning to 'const char *' from 'xmlChar *' (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign]
  xmlTreeIndentString = xmlStrdup((xmlChar *)StringValuePtr(string));
                      ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
compiling ruby_xml_attr.c
compiling ruby_xml_attr_decl.c
ruby_xml_attr_decl.c:57:53: warning: passing 'const xmlChar *' (aka 'const unsigned char *') to parameter of type 'const char *' converts between pointers to integer types with different sign [-Wpointer-sign]
    return rxml_new_cstr((const char*) xattr->name, xattr->doc->encoding);
                                                    ^~~~~~~~~~~~~~~~~~~~
./ruby_xml_encoding.h:11:51: note: passing argument to parameter 'xencoding' here
VALUE rxml_new_cstr(const char* xstr, const char* xencoding);
                                                  ^

完整错误大约是600行,但更多相同。

我已经在互联网上寻找解决方案并尝试了许多不同的东西,但没有运气。有什么想法吗?

3 个答案:

答案 0 :(得分:3)

我使用libxml2-dev安装了sudo apt-get install -y libxml2-dev

然后gem i libxml-ruby工作。

答案 1 :(得分:0)

安装最新版本的libxml-ruby并立即运行。

gem install libxml-ruby

答案 2 :(得分:0)

问题是我的Mac上没有安装一些必要的实用程序。

我通过运行一些brew安装来解决这个问题:

brew install libxml2 libxslt

brew install coreutils

安装coreutils后,我发现了很多的问题,我已经神奇地消失了。

另外,在安装Nokogiri时,我必须做一些非常接近的事情:

gem install nokogiri --use-system-libraries -- --with-ldflags

虽然我记不起我使用的确切选项