I am trying to build and install nokogiri
Rubygem on Mac OS X 10.9.2, which requires libxml2. Passing the --with-xml2-lib
and --with-xml2-include
option does not seem to take effect
$ 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
Setting LDFLAGS and CPPFLAGS does not work either (using Homebrew version of libxml2 instead of 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
The error output is always the same
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
Using Homebrew to install the libraries the gem depends on first and then setting NOKOGIRI_USE_SYSTEM_LIBRARIES=1
before actually installing the gem did the trick for me.
Summarising:
If previously installed, uninstall the gem:$ gem uninstall nokogiri
Use Homebrew to install libxml2
, libxslt
and libiconv
:$ brew install libxml2 libxslt libiconv
Install the gem specifying the paths to the libraries to be linked against:$ 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"
I had the same problem, but the following works for me:
gem install -- --with-opt-include=/usr/local/opt/libxml2/include/libxml2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With