How do I install libxml-ruby gem 2.3.2 on OSX El C

2019-09-07 07:20发布

问题:

I am trying to install an old project that runs on Ruby 1.8.7-p370 and has a dependency on an old version of the libxml-ruby 2.3.2 gem on a Mac running OS X El Capitan.

The problem is that when trying to install the gem it won't build the native extension. Here is the complete error upon running gem install libxml-ruby -v '2.3.2':

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

        /Users/myusername/.rbenv/versions/1.8.7-p370/bin/ruby extconf.rb
checking for socket() in -lsocket... no
checking for gethostbyname() in -lnsl... no
checking for atan() in -lm... 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
creating extconf.h
creating Makefile

make
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c libxml.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_attr.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_attr_decl.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_attributes.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_cbg.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_document.c
couldn't understand kern.osversion `15.6.0'
ruby_xml_document.c: In function ‘rxml_document_canonicalize’:
ruby_xml_document.c:334: warning: passing argument 4 of ‘xmlC14NDocDumpMemory’ from incompatible pointer type
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_dtd.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_encoding.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_error.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_html_parser.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_html_parser_context.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_html_parser_options.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_input_cbg.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_io.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_namespace.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_namespaces.c
couldn't understand kern.osversion `15.6.0'
/usr/local/bin/gcc-4.2 -I. -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include -DRUBY_EXTCONF_H=\"extconf.h\" -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  -I/Users/myusername/.rbenv/versions/1.8.7-p370/include  -fno-common  -O3 -Wno-error=shorten-64-to-32  -pipe -fno-common  -I/usr/include/libxml2 -I. -I/Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/1.8/i686-darwin15.6.0 -I. -I/usr/local/include  -c ruby_xml_node.c
couldn't understand kern.osversion `15.6.0'
ruby_xml_node.c: In function ‘rxml_node_to_s’:
ruby_xml_node.c:622: error: dereferencing pointer to incomplete type
ruby_xml_node.c:624: error: dereferencing pointer to incomplete type
make: *** [ruby_xml_node.o] Error 1


Gem files will remain installed in /Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/gems/1.8/gems/libxml-ruby-2.3.2 for inspection.
Results logged to /Users/myusername/.rbenv/versions/1.8.7-p370/lib/ruby/gems/1.8/gems/libxml-ruby-2.3.2/ext/libxml/gem_make.out

I have done some Googling but so far have not found a solution to the problem that works. Here are some of the things I have tried.

One suggestion was that uninstalling apple-gcc might work, but that leaves me without a compiler to build the native extension.

Another post suggested that this has to do with an incompatibility between libxml-ruby 2.3.2 and the more recent version of libxml that ships with OS X. However the following does not work since the MacOSX10.8 SDK does not seem to ship with Xcode anymore. Or am I missing something there?

export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk

What steps can I take to remedy this problem? Thanks for your help!

回答1:

Turns out the problem was indeed caused by an incompatible version of the ruby gem and the installed libxml version. In the end I choose to update to a slightly newer version of the gem so that it builds correctly.

If you really need exactly version 2.3.2 you can apparently also apply the following patch manually: https://github.com/xml4r/libxml-ruby/commit/1c4878f3fdcd0cdf2e0fd09a5e6147a6ed237cf0