Nokogiri: Problem installing v1.8.5

Created on 24 Oct 2018  路  9Comments  路  Source: sparklemotion/nokogiri

If you're having trouble installing Nokogiri ...

Have you tried following [the installation tutorial][tutorial]?
yes

What is the output of gem install?

$ gem install nokogiri -- --use-system-libraries --with-xml2-dir=/usr/include/libxml2 --with-xslt-dir=/usr/include/libxslt --with-exslt-dir=/usr/include/libexslt
Building native extensions with: '--use-system-libraries --with-xml2-dir=/usr/include/libxml2 --with-xslt-dir=/usr/include/libxslt --with-exslt-dir=/usr/include/libexslt'
This could take a while...
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    current directory: /home/<username>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.5/ext/nokogiri
/home/<username>/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20181026-26827-1sxhqft.rb extconf.rb --use-system-libraries --with-xml2-dir=/usr/include/libxml2 --with-xslt-dir=/usr/include/libxslt --with-exslt-dir=/usr/include/libexslt
checking if the C compiler accepts ... yes
Building nokogiri using system libraries.
ERROR: cannot discover where libxml2 is located on your system. please make sure `pkg-config` is installed.
*** 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=/home/<username>/.rbenv/versions/2.5.1/bin/$(RUBY_BASE_NAME)
    --help
    --clean
    --use-system-libraries
    --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-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-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-exslt-dir
    --with-exslt-include
    --without-exslt-include=${exslt-dir}/include
    --with-exslt-lib
    --without-exslt-lib=${exslt-dir}/lib

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

  /home/<username>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0-static/nokogiri-1.8.5/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/<username>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.5 for inspection.
Results logged to /home/<username>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0-static/nokogiri-1.8.5/gem_make.out

What are the contents of the mkmf.log file?

"gcc -o conftest -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-linux -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/ruby/backward -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0 -I. -I/home/<username>/.rbenv/versions/2.5.1/include    -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wno-maybe-uninitialized  conftest.c  -L. -L/home/<username>/.rbenv/versions/2.5.1/lib -Wl,-rpath,/home/<username>/.rbenv/versions/2.5.1/lib -L. -L/home/<username>/.rbenv/versions/2.5.1/lib  -fstack-protector -rdynamic -Wl,-export-dynamic     -Wl,-rpath,/home/<username>/.rbenv/versions/2.5.1/lib -L/home/<username>/.rbenv/versions/2.5.1/lib -lruby-static  -lpthread -ldl -lcrypt -lm   -lc "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

"gcc -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-linux -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/ruby/backward -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0 -I. -I/home/<username>/.rbenv/versions/2.5.1/include    -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wno-maybe-uninitialized    -Werror -c conftest.c"
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main() {return 0;}
/* end */

"gcc -E -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-linux -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/ruby/backward -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0 -I. -I/usr/include/libexslt/include -I/usr/include/libxslt/include -I/usr/include/libxml2/include -I/home/<username>/.rbenv/versions/2.5.1/include    -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wno-maybe-uninitialized  -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wmissing-noreturn -Winline  conftest.c -o conftest.i"
conftest.c:3:10: fatal error: libxml/xmlversion.h: No such file or directory
 #include <libxml/xmlversion.h>
          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <libxml/xmlversion.h>
/* end */

What operating system are you using?
Linux Mint 18.3

metuser-help

Most helpful comment

Here're the steps I took to fix my conda:

conda install gxx_linux-64
conda install -c anaconda gcc

After conda installed the packages, my C preproceessor paths are fixed, running gem install nokogiri works fine now.

Thanks for your help @flavorjones ! :smile:

All 9 comments

Hi, thanks for asking this question.

Just to level-set: my primary development machine has been Linux Mint 18 and 19, and it obviously works for me, so I'd like to focus initial exploration on what's different about a) our systems, and b) our user environments.

Can you first tell me if Nokogiri installs cleanly if you do not try to link against the system libraries? So instead of:

$ gem install nokogiri -- --use-system-libraries --with-xml2-dir=/usr/include/libxml2 --with-xslt-dir=/usr/include/libxslt --with-exslt-dir=/usr/include/libexslt

just run

$gem install nokogiri

This should tell us if the build tool chain (or how it's configured) is to blame, or if we should take a harder look at the libraries that are on disk (and maybe think about Mint upgrade issues or the apt packages).

@flavorjones

As requested, when I just run $gem install nokogiri

The output of gem install:

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

    current directory: /home/<username>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.5/ext/nokogiri
/home/<username>/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20181027-6831-1jtofrz.rb extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
Using mini_portile version 2.3.0
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2
*** 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=/home/<username>/.rbenv/versions/2.5.1/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

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

  /home/<username>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0-static/nokogiri-1.8.5/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/<username>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.5 for inspection.
Results logged to /home/<username>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0-static/nokogiri-1.8.5/gem_make.out

The contents of the mkmf.log file:

"gcc -o conftest -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-linux -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/ruby/backward -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0 -I. -I/home/<username>/.rbenv/versions/2.5.1/include    -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wno-maybe-uninitialized  conftest.c  -L. -L/home/<username>/.rbenv/versions/2.5.1/lib -Wl,-rpath,/home/<username>/.rbenv/versions/2.5.1/lib -L. -L/home/<username>/.rbenv/versions/2.5.1/lib  -fstack-protector -rdynamic -Wl,-export-dynamic     -Wl,-rpath,/home/<username>/.rbenv/versions/2.5.1/lib -L/home/<username>/.rbenv/versions/2.5.1/lib -lruby-static  -lpthread -ldl -lcrypt -lm   -lc "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

"gcc -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-linux -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/ruby/backward -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0 -I. -I/home/<username>/.rbenv/versions/2.5.1/include    -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wno-maybe-uninitialized    -Werror -c conftest.c"
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main() {return 0;}
/* end */

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

"gcc -o conftest -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-linux -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/ruby/backward -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0 -I. -I/home/<username>/.rbenv/versions/2.5.1/include    -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wno-maybe-uninitialized  -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wmissing-noreturn -Winline conftest.c  -L. -L/home/<username>/.rbenv/versions/2.5.1/lib -Wl,-rpath,/home/<username>/.rbenv/versions/2.5.1/lib -L. -L/home/<username>/.rbenv/versions/2.5.1/lib  -fstack-protector -rdynamic -Wl,-export-dynamic     -Wl,-rpath,/home/<username>/.rbenv/versions/2.5.1/lib -L/home/<username>/.rbenv/versions/2.5.1/lib -lruby-static -lz  -lpthread -ldl -lcrypt -lm   -lc "
conftest.c:3:10: fatal error: zlib.h: No such file or directory
 #include <zlib.h>
          ^~~~~~~~
compilation terminated.
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <zlib.h>
 4: 
 5: /*top*/
 6: extern int t(void);
 7: int main(int argc, char **argv)
 8: {
 9:   if (argc > 1000000) {
10:     printf("%p", &t);
11:   }
12: 
13:   return 0;
14: }
15: int t(void) { void ((*volatile p)()); p = (void ((*)()))gzdopen; return !p; }
/* end */

"gcc -o conftest -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-linux -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/ruby/backward -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0 -I. -I/home/<username>/.rbenv/versions/2.5.1/include    -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wno-maybe-uninitialized  -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wmissing-noreturn -Winline conftest.c  -L. -L/home/<username>/.rbenv/versions/2.5.1/lib -Wl,-rpath,/home/<username>/.rbenv/versions/2.5.1/lib -L. -L/home/<username>/.rbenv/versions/2.5.1/lib  -fstack-protector -rdynamic -Wl,-export-dynamic     -Wl,-rpath,/home/<username>/.rbenv/versions/2.5.1/lib -L/home/<username>/.rbenv/versions/2.5.1/lib -lruby-static -lz  -lpthread -ldl -lcrypt -lm   -lc "
conftest.c:3:10: fatal error: zlib.h: No such file or directory
 #include <zlib.h>
          ^~~~~~~~
compilation terminated.
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <zlib.h>
 4: 
 5: /*top*/
 6: extern int t(void);
 7: int main(int argc, char **argv)
 8: {
 9:   if (argc > 1000000) {
10:     printf("%p", &t);
11:   }
12: 
13:   return 0;
14: }
15: extern void gzdopen();
16: int t(void) { gzdopen(); return 0; }
/* end */

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

Thanks!

OK, this is helpful! Thank you.

The first error seen is:

checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2

followed by

conftest.c:3:10: fatal error: zlib.h: No such file or directory

which is pretty good evidence that your system doesn't have zlib1g-dev installed.

The installation tutorial is up to date and does have this as the first step for Debian-based systems:

sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev

Can you please try that and then try again to install the gem using vendored libraries?

I install these packages and this is what I got:

$ sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
build-essential is already the newest version (12.1ubuntu2).
liblzma-dev is already the newest version (5.1.1alpha+20120614-2ubuntu2).
ruby-dev is already the newest version (1:2.3.0+1).
patch is already the newest version (2.7.5-1ubuntu0.16.04.1).
zlib1g-dev is already the newest version (1:1.2.8.dfsg-2ubuntu4.1).
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.

Output of gem install nokogiri:

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

    current directory: /home/<username>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.5/ext/nokogiri
/home/<username>/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20181030-24481-1m5c6lj.rb extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
Using mini_portile version 2.3.0
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2
*** 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=/home/<username>/.rbenv/versions/2.5.1/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

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

  /home/<username>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0-static/nokogiri-1.8.5/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/<username>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.5 for inspection.
Results logged to /home/<username>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0-static/nokogiri-1.8.5/gem_make.out

mkmf.log output:

"gcc -o conftest -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-linux -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/ruby/backward -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0 -I. -I/home/<username>/.rbenv/versions/2.5.1/include    -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wno-maybe-uninitialized  conftest.c  -L. -L/home/<username>/.rbenv/versions/2.5.1/lib -Wl,-rpath,/home/<username>/.rbenv/versions/2.5.1/lib -L. -L/home/<username>/.rbenv/versions/2.5.1/lib  -fstack-protector -rdynamic -Wl,-export-dynamic     -Wl,-rpath,/home/<username>/.rbenv/versions/2.5.1/lib -L/home/<username>/.rbenv/versions/2.5.1/lib -lruby-static  -lpthread -ldl -lcrypt -lm   -lc "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

"gcc -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-linux -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/ruby/backward -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0 -I. -I/home/<username>/.rbenv/versions/2.5.1/include    -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wno-maybe-uninitialized    -Werror -c conftest.c"
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main() {return 0;}
/* end */

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

"gcc -o conftest -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-linux -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/ruby/backward -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0 -I. -I/home/<username>/.rbenv/versions/2.5.1/include    -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wno-maybe-uninitialized  -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wmissing-noreturn -Winline conftest.c  -L. -L/home/<username>/.rbenv/versions/2.5.1/lib -Wl,-rpath,/home/<username>/.rbenv/versions/2.5.1/lib -L. -L/home/<username>/.rbenv/versions/2.5.1/lib  -fstack-protector -rdynamic -Wl,-export-dynamic     -Wl,-rpath,/home/<username>/.rbenv/versions/2.5.1/lib -L/home/<username>/.rbenv/versions/2.5.1/lib -lruby-static -lz  -lpthread -ldl -lcrypt -lm   -lc "
conftest.c:3:10: fatal error: zlib.h: No such file or directory
 #include <zlib.h>
          ^~~~~~~~
compilation terminated.
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <zlib.h>
 4: 
 5: /*top*/
 6: extern int t(void);
 7: int main(int argc, char **argv)
 8: {
 9:   if (argc > 1000000) {
10:     printf("%p", &t);
11:   }
12: 
13:   return 0;
14: }
15: int t(void) { void ((*volatile p)()); p = (void ((*)()))gzdopen; return !p; }
/* end */

"gcc -o conftest -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-linux -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0/ruby/backward -I/home/<username>/.rbenv/versions/2.5.1/include/ruby-2.5.0 -I. -I/home/<username>/.rbenv/versions/2.5.1/include    -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wno-maybe-uninitialized  -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wmissing-noreturn -Winline conftest.c  -L. -L/home/<username>/.rbenv/versions/2.5.1/lib -Wl,-rpath,/home/<username>/.rbenv/versions/2.5.1/lib -L. -L/home/<username>/.rbenv/versions/2.5.1/lib  -fstack-protector -rdynamic -Wl,-export-dynamic     -Wl,-rpath,/home/<username>/.rbenv/versions/2.5.1/lib -L/home/<username>/.rbenv/versions/2.5.1/lib -lruby-static -lz  -lpthread -ldl -lcrypt -lm   -lc "
conftest.c:3:10: fatal error: zlib.h: No such file or directory
 #include <zlib.h>
          ^~~~~~~~
compilation terminated.
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: #include <zlib.h>
 4: 
 5: /*top*/
 6: extern int t(void);
 7: int main(int argc, char **argv)
 8: {
 9:   if (argc > 1000000) {
10:     printf("%p", &t);
11:   }
12: 
13:   return 0;
14: }
15: extern void gzdopen();
16: int t(void) { gzdopen(); return 0; }
/* end */

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

OK, that's helpful, thank you.

What I notice here is that gcc is still unable to find the header file zlib.h:

The zlib1g-dev package does contain this file:

$ dpkg -L zlib1g-dev | fgrep zlib.h
/usr/include/zlib.h

so there's something about how your environment is configured that's causing gcc not to find this file.

Can you run this and report back the output (note the backticks)? It will tell you the paths where the C preprocessor looks for header files.

`gcc -print-prog-name=cc1plus` -v

On my system, I get:

$ `gcc -print-prog-name=cc1plus` -v
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/7
 /usr/include/x86_64-linux-gnu/c++/7
 /usr/include/c++/7/backward
 /usr/lib/gcc/x86_64-linux-gnu/7/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed
 /usr/include
End of search list.
^C

You can see that /usr/include is listed. What output do you see?

I get the following report:

$ `gcc -print-prog-name=cc1plus` -v
ignoring nonexistent directory "/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/gcc_built/x86_64-conda_cos6-linux-gnu/include/c++/7.3.0"
ignoring nonexistent directory "/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/gcc_built/x86_64-conda_cos6-linux-gnu/include/c++/7.3.0/x86_64-conda_cos6-linux-gnu"
ignoring nonexistent directory "/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/gcc_built/x86_64-conda_cos6-linux-gnu/include/c++/7.3.0/backward"
ignoring nonexistent directory "/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/gcc_built/lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/include"
ignoring nonexistent directory "/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/gcc_built/x86_64-conda_cos6-linux-gnu/sysroot/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/gcc_built/x86_64-conda_cos6-linux-gnu/sysroot/include"
ignoring nonexistent directory "/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/gcc_built/lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/include-fixed"
ignoring nonexistent directory "/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/gcc_built/x86_64-conda_cos6-linux-gnu/include"
ignoring nonexistent directory "/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/gcc_built/x86_64-conda_cos6-linux-gnu/sysroot/usr/include"
#include "..." search starts here:
#include <...> search starts here:
End of search list.

Interesting, as the report states, the username rdonnelly is not mine.

@shawnngtq OK, this tells me that you have something specific in your environment or in your machine's configuration that's overriding the paths usually searched by the compiler toolchain. So my bet is that you'll have trouble compiling any rubygem with a C extension (e.g., eventmachine), and this is not specific to Nokogiri.

It looks like maybe you have (or had) conda configured? It also looks like none of those directories exist anymore. My advice would be to investigate what happened there.

Here're the steps I took to fix my conda:

conda install gxx_linux-64
conda install -c anaconda gcc

After conda installed the packages, my C preproceessor paths are fixed, running gem install nokogiri works fine now.

Thanks for your help @flavorjones ! :smile:

woot! Thanks for closing the loop for us, and I'm happy you got everything working again.

Was this page helpful?
0 / 5 - 0 ratings