Nokogiri 1.6.8 Install Fails on Mac OS X with xz installed from Homebrew #1483

Closed
halostatue opened this Issue Jun 7, 2016 · 51 comments

Projects

None yet
@halostatue

Action:

brew install xz
gem install nokogiri -v 1.6.8

Expected:

Nokogiri 1.6.8 installs correctly.

Actual:

Restoring gems to pristine condition...
Building native extensions.  This could take a while...
ERROR:  While executing gem ... (Gem::Ext::BuildError)
    ERROR: Failed to build gem native extension.

    current directory: /Users/austin/.gem/ruby/2.3.0/gems/nokogiri-1.6.8/ext/nokogiri
/Users/austin/.rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160607-71935-1m9be2b.rb extconf.rb
Using pkg-config version 1.1.7
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
Using mini_portile version 2.1.0
checking for iconv.h... yes
checking for gzdopen() in -lz... yes
checking for iconv... yes
************************************************************************
IMPORTANT NOTICE:

Building Nokogiri with a packaged version of libxml2-2.9.4.

Team Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:

    gem install nokogiri -- --use-system-libraries
        [--with-xml2-config=/path/to/xml2-config]
        [--with-xslt-config=/path/to/xslt-config]

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri --use-system-libraries
    bundle install

Note, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.
************************************************************************
Extracting libxml2-2.9.4.tar.gz into tmp/x86_64-apple-darwin15.3.0/ports/libxml2/2.9.4... OK
Running 'configure' for libxml2 2.9.4... OK
Running 'compile' for libxml2 2.9.4... ERROR, review '/Users/austin/.gem/ruby/2.3.0/gems/nokogiri-1.6.8/ext/nokogiri/tmp/x86_64-apple-darwin15.3.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
========================================================================
*** 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
    --without-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=/Users/austin/.rubies/ruby-2.3.0/bin/$(RUBY_BASE_NAME)
    --help
    --clean
    --use-system-libraries
    --enable-static
    --disable-static
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --enable-cross-build
    --disable-cross-build
/Users/austin/.gem/ruby/2.3.0/gems/mini_portile2-2.1.0/lib/mini_portile2/mini_portile.rb:366:in `block in execute': Failed to complete compile task (RuntimeError)
    from /Users/austin/.gem/ruby/2.3.0/gems/mini_portile2-2.1.0/lib/mini_portile2/mini_portile.rb:337:in `chdir'
    from /Users/austin/.gem/ruby/2.3.0/gems/mini_portile2-2.1.0/lib/mini_portile2/mini_portile.rb:337:in `execute'
    from /Users/austin/.gem/ruby/2.3.0/gems/mini_portile2-2.1.0/lib/mini_portile2/mini_portile.rb:111:in `compile'
    from /Users/austin/.gem/ruby/2.3.0/gems/mini_portile2-2.1.0/lib/mini_portile2/mini_portile.rb:150:in `cook'
    from extconf.rb:364:in `block (2 levels) in process_recipe'
    from extconf.rb:257:in `block in chdir_for_build'
    from extconf.rb:256:in `chdir'
    from extconf.rb:256:in `chdir_for_build'
    from extconf.rb:363:in `block in process_recipe'
    from extconf.rb:262:in `tap'
    from extconf.rb:262:in `process_recipe'
    from extconf.rb:555:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/austin/.gem/ruby/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/nokogiri-1.6.8/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/austin/.gem/ruby/2.3.0/gems/nokogiri-1.6.8 for inspection.
Results logged to /Users/austin/.gem/ruby/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/nokogiri-1.6.8/gem_make.out
gem pristine nokogiri -v 1.6.8  9.23s user 7.56s system 92% cpu 18.089 total

When I do:

brew uninstall xz
gem install nokogiri -v 1.6.8

Nokogiri 1.6.8 installs correctly.

@kenaniah
kenaniah commented Jun 7, 2016

I had the same build failure. brew uninstall xz indeed allows nokogiri to compile.

@md5
md5 commented Jun 8, 2016

Although the brew uninstall xz workaround did work for me, I also ran across #1445, which has the same compilation error. It turns out that running xcode-select --install also worked for me, though I could have sworn I had already run that months ago.

@flavorjones
Member

summoning @aramprice

@aramprice
aramprice commented Jun 8, 2016 edited

tl;dr => xz installs a version of liblzma which can not be linked against when building nokogiri dependencies

Here's the info I've been able to dig up when running into this issue; resolved with the similar brew uninstall xz dance.

Looking in the .../nokogiri-1.6.8/mkmf.log there is the following message (in my case not at the end of the file):

ld: warning: ignoring file /usr/local/lib/liblzma.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib/liblzma.dylib

It turns out that that /usr/local/lib/liblzma.dylib is part of the brew xz formulae:

brew info liblzma
lzma is now part of the xz formula.

Uninstalling allows the libxml compile to succeed. The unfortunate thing is that xz is a (recommended) dependency of ag (the_silver_searcher) so most people end up with it.

> brew info ag
the_silver_searcher: stable 0.32.0 (bottled), HEAD
Code-search similar to ack
https://github.com/ggreer/the_silver_searcher
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/the_silver_searcher.rb
==> Dependencies
Build: autoconf ✘, automake ✘, pkg-config ✘
Required: pcre ✘
Recommended: xz ✘
==> Options
--without-xz
    Build without xz support
--HEAD
    Install HEAD version

Configuration:

  • osx: Darwin 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64
  • ruby (system) ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
@DomT4
DomT4 commented Jun 9, 2016

ld: warning: ignoring file /usr/local/lib/liblzma.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib/liblzma.dylib

This sounds like you want to nudge people to brew install xz --universal. I'm unable to reproduce this specific example locally though with a vanilla brew install xz in /usr/local and gem 2.5.1, ruby 2.3.1p112.

************************************************************************
Extracting libxslt-1.1.29.tar.gz into tmp/x86_64-apple-darwin15.5.0/ports/libxslt/1.1.29... OK
Running 'configure' for libxslt 1.1.29... OK
Running 'compile' for libxslt 1.1.29... OK
Running 'install' for libxslt 1.1.29... OK
Activating libxslt 1.1.29 (from /usr/local/var/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/nokogiri-1.6.8/ports/x86_64-apple-darwin15.5.0/libxslt/1.1.29)...
checking for main() in -llzma... yes
checking for xmlParseDoc() in libxml/parser.h... yes
checking for xsltParseStylesheetDoc() in libxslt/xslt.h... yes
checking for exsltFuncRegister() in libexslt/exslt.h... yes
checking for xmlHasFeature()... yes
checking for xmlFirstElementChild()... yes
checking for xmlRelaxNGSetParserStructuredErrors()... yes
checking for xmlRelaxNGSetParserStructuredErrors()... yes
checking for xmlRelaxNGSetValidStructuredErrors()... yes
checking for xmlSchemaSetValidStructuredErrors()... yes
checking for xmlSchemaSetParserStructuredErrors()... yes
creating Makefile
@aramprice
aramprice commented Jun 9, 2016 edited

@DomT4 installing with --universal seemed to resolve the issue for me.

I also tried --without-xz which resulted in another "incompatible architecture" error for an iconv check

@DomT4
DomT4 commented Jun 9, 2016

which resulted in another "incompatible architecture" error for an iconv check

That's a bit odd. Anything in brew doctor or brew list | grep iconv?

@aramprice

No problems reported by brew doctor and nothing listed for iconv.

The actual culprit is probably further back in the mkmf.log. I'll try to reproduce the error from having ag installed --without-xz and post them.

@jonbcampos

If it helps anyone, I was able to get it build properly after a brew uninstall xz without having to do the recommended brew uinstall -force xz thus leaving xz 5.2.1 still on the computer. I don't know if this is good or bad though.

@aramprice

Duplicated with on the following configuration:

→ uname -a
Darwin HOSTNAME 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64

→ /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
  Gem::VERSION => 2.6.4
  Bundler::VERSION => 1.12.5

→ brew -v
Homebrew 0.9.9 (git revision 11d4; last commit 2016-06-08)
Homebrew/homebrew-core (git revision 2343; last commit 2016-06-10)

→ brew info xz
xz: stable 5.2.2 (bottled)
General-purpose data compression with high compression ratio
http://tukaani.org/xz/
/usr/local/Cellar/xz/5.2.2 (91 files, 1.4M) *
  Poured from bottle on 2016-06-10 at 14:45:50
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/xz.rb
==> Options
--universal
    Build a universal binary

→ xcode-select -p
/Library/Developer/CommandLineTools

Output from bundle:

Installing nokogiri 1.6.8 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: tmp/ruby/2.0.0/gems/nokogiri-1.6.8/ext/nokogiri
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20160610-69863-1yfw0mn.rb extconf.rb
Using pkg-config version 1.1.7
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
Using mini_portile version 2.1.0
checking for iconv.h... yes
checking for gzdopen() in -lz... yes
checking for iconv... yes
************************************************************************
IMPORTANT NOTICE:

Building Nokogiri with a packaged version of libxml2-2.9.4.

Team Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:

    gem install nokogiri -- --use-system-libraries
        [--with-xml2-config=/path/to/xml2-config]
        [--with-xslt-config=/path/to/xslt-config]

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri --use-system-libraries
    bundle install

Note, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.
************************************************************************
Extracting libxml2-2.9.4.tar.gz into tmp/x86_64-apple-darwin15/ports/libxml2/2.9.4... OK
Running 'configure' for libxml2 2.9.4... OK
Running 'compile' for libxml2 2.9.4... ERROR, review 'tmp/ruby/2.0.0/gems/nokogiri-1.6.8/ext/nokogiri/tmp/x86_64-apple-darwin15/ports/libxml2/2.9.4/compile.log' to see what happened. Last lines are:
========================================================================
  CCLD     libxml2.la
  CC       testdso.lo
  CCLD     testdso.la
  CC       xmllint.o
  CCLD     xmllint
ld: warning: ignoring file /usr/local/Cellar/xz/5.2.2/lib/liblzma.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/xz/5.2.2/lib/liblzma.dylib
Undefined symbols for architecture i386:
  "_lzma_auto_decoder", referenced from:
      _xz_head in libxml2.a(xzlib.o)
  "_lzma_code", referenced from:
      _xz_decomp in libxml2.a(xzlib.o)
  "_lzma_end", referenced from:
      ___libxml2_xzclose in libxml2.a(xzlib.o)
  "_lzma_properties_decode", referenced from:
      _is_format_lzma in libxml2.a(xzlib.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [xmllint] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
========================================================================
*** 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
    --without-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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    --help
    --clean
    --use-system-libraries
    --enable-static
    --disable-static
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --enable-cross-build
    --disable-cross-build
tmp/ruby/2.0.0/gems/mini_portile2-2.1.0/lib/mini_portile2/mini_portile.rb:366:in `block in execute': Failed to complete compile task (RuntimeError)
    from tmp/ruby/2.0.0/gems/mini_portile2-2.1.0/lib/mini_portile2/mini_portile.rb:337:in `chdir'
    from tmp/ruby/2.0.0/gems/mini_portile2-2.1.0/lib/mini_portile2/mini_portile.rb:337:in `execute'
    from tmp/ruby/2.0.0/gems/mini_portile2-2.1.0/lib/mini_portile2/mini_portile.rb:111:in `compile'
    from tmp/ruby/2.0.0/gems/mini_portile2-2.1.0/lib/mini_portile2/mini_portile.rb:150:in `cook'
    from extconf.rb:364:in `block (2 levels) in process_recipe'
    from extconf.rb:257:in `block in chdir_for_build'
    from extconf.rb:256:in `chdir'
    from extconf.rb:256:in `chdir_for_build'
    from extconf.rb:363:in `block in process_recipe'
    from extconf.rb:262:in `tap'
    from extconf.rb:262:in `process_recipe'
    from extconf.rb:555:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  tmp/ruby/2.0.0/extensions/universal-darwin-15/2.0.0/nokogiri-1.6.8/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in tmp/ruby/2.0.0/gems/nokogiri-1.6.8 for inspection.
Results logged to tmp/ruby/2.0.0/extensions/universal-darwin-15/2.0.0/nokogiri-1.6.8/gem_make.out

Contents of mkmf.log:

→ cat ruby/2.0.0/extensions/universal-darwin-15/2.0.0/nokogiri-1.6.8/mkmf.log
"xcrun clang -o conftest -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin15 -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_SYNC_BUILTINS  conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib -L. -L/usr/local/lib   -arch x86_64 -arch i386   -lruby.2.0.0  -lpthread -ldl -lobjc  "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

"xcrun clang -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin15 -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_SYNC_BUILTINS   -arch x86_64 -arch i386  -c conftest.c"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */

"xcrun clang -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin15 -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_SYNC_BUILTINS  -Wno-error=unused-command-line-argument-hard-error-in-future  -arch x86_64 -arch i386  -c conftest.c"
warning: unknown warning option '-Werror=unused-command-line-argument-hard-error-in-future'; did you mean '-Werror=unused-command-line-argument'? [-Wunknown-warning-option]
1 warning generated.
warning: unknown warning option '-Werror=unused-command-line-argument-hard-error-in-future'; did you mean '-Werror=unused-command-line-argument'? [-Wunknown-warning-option]
1 warning generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */

have_header: checking for iconv.h... -------------------- yes

"xcrun clang -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin15 -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_SYNC_BUILTINS   -arch x86_64 -arch i386  -c conftest.c"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <iconv.h>
/* end */

--------------------

have_library: checking for gzdopen() in -lz... -------------------- yes

"xcrun clang -o conftest -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin15 -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_SYNC_BUILTINS  conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib -L. -L/usr/local/lib   -arch x86_64 -arch i386   -lruby.2.0.0 -lz  -lpthread -ldl -lobjc  "
checked program was:
/* begin */
 1: #include "ruby.h"
 2:
 3: #include <zlib.h>
 4:
 5: /*top*/
 6: extern int t(void);
 7: int t(void) { void ((*volatile p)()); p = (void ((*)()))gzdopen; return 0; }
 8: int main(int argc, char **argv)
 9: {
10:   if (argc > 1000000) {
11:     printf("%p", &t);
12:   }
13:
14:   return 0;
15: }
/* end */

--------------------

have_iconv?: checking for iconv... -------------------- yes

"xcrun clang -o conftest -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin15 -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_SYNC_BUILTINS  conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib -L. -L/usr/local/lib   -arch x86_64 -arch i386   -lruby.2.0.0  -lpthread -ldl -lobjc  "
Undefined symbols for architecture x86_64:
  "_iconv", referenced from:
      _main in conftest-ba1623.o
  "_iconv_open", referenced from:
      _main in conftest-ba1623.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
 1: #include "ruby.h"
 2:
 3: #include <stdlib.h>
 4: #include <iconv.h>
 5:
 6: int main(void)
 7: {
 8:     iconv_t cd = iconv_open("", "");
 9:     iconv(cd, NULL, NULL, NULL, NULL);
10:     return EXIT_SUCCESS;
11: }
/* end */

"xcrun clang -o conftest -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin15 -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_SYNC_BUILTINS  conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib -L. -L/usr/local/lib   -arch x86_64 -arch i386   -lruby.2.0.0 -liconv -lpthread -ldl -lobjc  "
checked program was:
/* begin */
 1: #include "ruby.h"
 2:
 3: #include <stdlib.h>
 4: #include <iconv.h>
 5:
 6: int main(void)
 7: {
 8:     iconv_t cd = iconv_open("", "");
 9:     iconv(cd, NULL, NULL, NULL, NULL);
10:     return EXIT_SUCCESS;
11: }
/* end */

--------------------
@BenMorganIO

This worked for me:

gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --use-system-libraries
@au5ton
au5ton commented Jun 24, 2016

This worked for me when attempting to install github/pages-gem. Thanks @md5.

@CyborgMaster

xcode-select --install worked for me

@phantompatrol
phantompatrol commented Jul 11, 2016 edited

Related or dupe to #1486? Given that (subjectively) the symptoms and solution were similar for me.

@timurcatakli

I had the same nokogiri install problem. My repo folder was in a box.com sync folder. I moved it to another folder and it installed without any problems. So make sure that you are not using a box.com folder.

Thanks

@halorium

xcode-select --install worked for me.

@jatorresdev

xcode-select --install worked for me.

@njia
njia commented Aug 8, 2016 edited

brew unlink xz is enough, you don't have to uninstall it. It worked for me on CentOS7 VM (Linuxbrew)

@halostatue

@njia Yes. You will need to relink it before you do almost anything else with brew, and xcode-select --install did not work for me recently (because I had done it more than a year ago).

@wenweih
wenweih commented Aug 9, 2016 edited

before bundle install , you should run this command

bundle config build.nokogiri --use-system-libraries --with-xml2-include=/usr/include/libxml2/

or add config in project project_path/.bundle/config and add the content into it

---
BUNDLE_PATH: vendor/bundle
BUNDLE_BUILD__MYSQL: "--with-mysql-config=/usr/local/bin/mysql_config"

gem install for system env, just xcode-select --install

@dyndna
dyndna commented Aug 20, 2016

As per @wenweih, following worked instead of doing brew uninstall xz

brew install libxml2
bundle config build.nokogiri --use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2
bundle install
# or if updating github-pages gem
bundle update github-pages

My gemfile for github-pages based website:

source 'https://rubygems.org'

group :jekyll_plugins do
gem 'github-pages', '>= 78'
end

group :jekyll_misc_plugins do
gem 'jekyll-compose', '>= 0.4.1'
gem 'font-awesome-sass', '>= 4.6.2'
gem 'travis', '>= 1.8.2'
gem 'jekyll-mentions', '>= 1.1.2'
end
@lgh06
lgh06 commented Aug 31, 2016

same issue ,use jekyll on mac... uninstalled xz,it works for me...but i do not really know what is xz...

@sparkrevolutions

I tried all of the above to no avail. For me, the solution was to use rvm to manage my version of ruby. I could then install nokogiri fine!

\curl -sSL https://get.rvm.io | bash -s stable --ruby

@jennabelle

brew uninstall xz
gem install rails

Worked for me! Thanks y'all!

@schneidexe
schneidexe commented Sep 9, 2016 edited

It's not particularly brew but related. I use macports and had the same issue. I could solve it by re-installing xz and libxml2 from sources instead of using the pre-compiled binary (takes a while ;)):

sudo port -s -v install xz libxml2 +universal

Also you need to use system libs:

bundle config build.nokogiri --use-system-libraries
@McGar
McGar commented Sep 16, 2016

I had the similiar nokogiri install problem

A little bit different :
seems failed at compiler step:
checking if the C compiler accepts ... *** extconf.rb failed ***

gem install nokogiri -v '1.6.8'

or

gem install nokogiri -v 1.6.8 -- --with-iconv-dir=xcode-select -p/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr --with-xml2-include=xcode-select -p/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2

Here is the whole error log:

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

/Users/nywlsb/.rvm/rubies/ruby-1.9.3-p392/bin/ruby -r ./siteconf20160916-11734-hblu9v.rb extconf.rb

Using pkg-config version 1.1.7
checking if the C compiler accepts ... *** 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=/Users/nywlsb/.rvm/rubies/ruby-1.9.3-p392/bin/ruby
--help
--clean
/Users/nywlsb/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/mkmf.rb:381:in try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /Users/nywlsb/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/mkmf.rb:491:inblock in try_compile'
from /Users/nywlsb/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/mkmf.rb:441:in with_werror' from /Users/nywlsb/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/mkmf.rb:491:intry_compile'
from extconf.rb:138:in nokogiri_try_compile' from extconf.rb:162:inblock in add_cflags'
from /Users/nywlsb/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/mkmf.rb:535:in with_cflags' from extconf.rb:161:inadd_cflags'
from extconf.rb:414:in `

'

extconf failed, exit code 1

Gem files will remain installed in /Users/nywlsb/.rvm/gems/ruby-1.9.3-p392@aiview_dashboard_ror/gems/nokogiri-1.6.8 for inspection.

any ideas guys

@bender75

removing macports bin from $PATH resolves this issue for me on macOS sierra (10.11)

@esambo
esambo commented Oct 1, 2016

brew doctor mentioned: Your system is ready to brew. BEFORE I ran xcode-select --install as suggested above to fix this issue!

I'm on:

  • macOS Sierra Version 10.12
  • Xcode Version 8.0 (8A218a)
  • xcode-select --version 2345.1. (I do not know what it was before I did the --install)
  • ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
  • nokogiri-1.6.8 (now installed successfully)
@flavorjones
Member

If someone can boil down the advice here into a PR for the installation tutorial, I'd be very grateful.

@flavorjones flavorjones closed this Oct 2, 2016
@plentz
Contributor
plentz commented Oct 3, 2016
brew unlink xz
gem install nokogiri

did the trick for me.

@flavorjones
Member

If someone can boil down the advice here into a PR for the installation tutorial, I'd be very grateful.

@esambo
esambo commented Oct 3, 2016

I don't think uninstalling packages should be the proper solution. What is wrong with updating the Command Line Tools (xcode-select --install)? I think the bigger problem is why brew doctor didn't mention that it needed to be done.

@halostatue

@esambo Because xcode-select --install doesn’t actually work for everyone. I’m completely up to date with the Xcode Command Line Tools and I cannot install Nokogiri without doing brew unlink xz; gem install nokogiri; brew link xz, or without doing the universal install (brew install xz --universal) which I never remember to do because I’ve never installed xz directly, but only as a transitive dependency (and there are lots of Homebrew things which require it transitively).

IMO, @flavorjones, this should not be closed until there is a PR as you have requested, although I would agree that this thread should probably be locked because of the mixed information in the thread. The real problem is that Homebrew (without --universal) installs versions which are x64-only, but the Nokogiri and/or Ruby builds are x86 and x64 universal, which are not compatible with x64-only libraries.

@uberllama
uberllama commented Oct 3, 2016 edited

xcode-select --install did not work for me. Currently a blocking issue on updating other gems.

Update: Correction, after updating to the latest brew I seem to be good to go. Weird.

@flavorjones
Member

@halostatue I'd greatly appreciate if someone who cares deeply about OSX support would submit a PR to the documentation.

You clearly know more than I do about OSX binaries and support, and I have no way to either reproduce this error nor verify that what you're suggesting is correct, as I'm a Linux user. So I'd like to gently suggest that you're in a better position than I am to craft clear instructions for future OSX users of Nokogiri.

@tishpr
tishpr commented Oct 7, 2016

brew uinstall -force xz worked for me, so far, I think...

@caiocesarf

xcode-select --install worked for me.

@tishpr
tishpr commented Oct 9, 2016

Seemed to work for me too, thanks!

On Oct 7, 2016 9:54 PM, "Caio César" notifications@github.com wrote:

xcode-select --install worked for me.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#1483 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADCnbKdI888VXkj6EuUhn800CeQYPKHkks5qxyHvgaJpZM4IwSGE
.

@MtnBiker
MtnBiker commented Oct 9, 2016 edited

As per @dyndna and @wenweih, the following worked for me for a related problem.

brew install libxml2
bundle config build.nokogiri --use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2
bundle install

See here for complete discussion: http://stackoverflow.com/questions/39937394/gem-install-nokogiri-v-1-6-8-1-fails/

xcode-select --install didn't work.

MacOSX Sierra, Ruby 2.3.1

@halostatue

@MtnBiker, can you please retry without the homebrew libxml2 and using the brew unlink xz; bundle install; brew link xz? At some point, I’m going to put together a PR for the installation document as @flavorjones requested, and while xcode-select --install will work for some, your solution is strongly recommended against by the Nokogiri team because they have a patched version of libxml2 that they prefer to use.

@MtnBiker
MtnBiker commented Oct 9, 2016

@halostatue The key word in my response was "related." I'm not (knowingly anyway) using xz. Someone posted a link to this thread in response to a problem I was having with nokigiri. So trying what you suggest probably doesn't make sense in my case. And in any case since things are working now I'm not going to mess with it.

@timvisher timvisher referenced this issue in test-kitchen/kitchen-docker Oct 9, 2016
Closed

Support development on macOS 10.12 #234

@halostatue

@MtnBiker; if you’re using homebrew, you’re probably using xz whether you realize it or not. If you ran brew uses --installed xz, you will probably see results. On my system, imagemagick, io, python3, and the_silver_searcher all depend on xz.

@MtnBiker
MtnBiker commented Oct 9, 2016 edited

@halostatue brew unlink xz; bundle install; brew link xz ran without problems. Does that show that it would have solved the nokogiri problem?

I was going to ask earlier how to determine dependencies, but you answered it. Hence followed through on your original request.

@halostatue
halostatue commented Oct 10, 2016 edited

It seems that it would have, thanks for checking that out, @MtnBiker.

@martinstreicher
martinstreicher commented Oct 13, 2016 edited

bundle config build.nokogiri --use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2 worked for me.

@lawrend
lawrend commented Oct 16, 2016

had the same error (unsigned short) when trying to install nokogiri.
I'd updated xcode from 7.x to 8 about an hour prior but had yet to update command line so xcode-select --install worked for me.

@halostatue halostatue added a commit to halostatue/nokogiri.org-tutorials that referenced this issue Oct 17, 2016
@halostatue halostatue Properly document macOS install issues
This properly resolves sparklemotion/nokogiri#1483 with meaningfully updated
documentation.
e764d8e
@flavorjones
Member

Documentation is now online for brew unlink xz.

@idcrook idcrook added a commit to idcrook/timetemp that referenced this issue Nov 6, 2016
@idcrook idcrook got bundle install to work 4c006b8
@ylluminate

Same problem here, had to: brew unlink xz; gem install nokogiri; brew link xz

@ALFmachine

xcode-select --install worked for me

@tkosaka1976

I also need to do : brew unlink xz; gem install nokogiri; brew link xz
not solved via : xcode-select --install

@flavorjones
Member

All of this is in the installation tutorial!

http://www.nokogiri.org/tutorials/installing_nokogiri.html#mac_os_x

Locking this issue.

@flavorjones flavorjones locked and limited conversation to collaborators Nov 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.