Could you help me, please?
I found an issue when building libxml2 2.9.4 during installation of nokogiri. (gem install nokogiri)
The macro HAVE_LZMA_H is NOT set to 1, so that libxml2 cannot find LZMA_OK in lzma/base.h. In fact, it doesn't include this header files. Maybe something is wrong in extconf.rb. How can I fix it manually?
Thanks
ENV:
OS: macOS sierra + Homebrew
Dependency Libs: xz (lzma.h included) had been installed
Ruby: 2.3.1 (with rbenv 1.0.0)
For now I installed nokogiri with homebrew libxml2.
PKG_CONFIG_PATH="$(brew --prefix)/opt/libxml2/lib/pkgconfig" \
LDFLAGS="-L$(brew --prefix)/opt/libxml2/lib" \
CPPFLAGS="-I(brew --prefix)/opt/libxml2/include" \
gem install nokogiri -- --use-system-libraries
(all config are from brew info libxml2)
excerpt from the gem_make.out when just running gem install nokogiri
************************************************************************
Extracting libxml2-2.9.4.tar.gz into tmp/x86_64-apple-darwin16.0.0/ports/libxml2/2.9.4... OK
Running 'configure' for libxml2 2.9.4... OK
Running 'compile' for libxml2 2.9.4... ERROR, review '<homedir>/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nokogiri-1.6.8/ext/nokogiri/tmp/x86_64-apple-darwin16.0.0/ports/libxml2/2.9.4/compile.log' to see what happened. Last lines are:
========================================================================
unsigned short* in = (unsigned short*) inb;
^~~~~~~~~~~~~~~~~~~~~
encoding.c:815:27: warning: cast from 'unsigned char *' to 'unsigned short *' increases required alignment from 1 to 2 [-Wcast-align]
unsigned short* out = (unsigned short*) outb;
^~~~~~~~~~~~~~~~~~~~~~
4 warnings generated.
CC error.lo
CC parserInternals.lo
CC parser.lo
CC tree.lo
CC hash.lo
CC list.lo
CC xmlIO.lo
xmlIO.c:1450:52: error: use of undeclared identifier 'LZMA_OK'
ret = (__libxml2_xzclose((xzFile) context) == LZMA_OK ) ? 0 : -1;
^
1 error generated.
make[2]: *** [xmlIO.lo] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
Try xcode-select --install and then retry the gem install nokogiri command.
@scharfie that works! It's strange since I had no problem with building ruby or other gems with native extensions..
Thanks @scharfie, it works. I think it's because I was using the building tools within Xcode itself which could not find the path of XZ outside of Xcode sandbox, but the command tools of Xcode could find it.
Thanks @scharfie, worked like a charm!
Future readers, please go to the nokogiri.org installation tutorial for help installing Nokogiri.
Most helpful comment
Try
xcode-select --installand then retry thegem install nokogiricommand.