Installing nokogiri - Failed to build gem native extension - ruby-on-rails

While installing Nokogiri on Ubuntu 12, I got an error:
Installing nokogiri (1.4.4) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
extconf.rb:10: Use RbConfig instead of obsolete and deprecated Config.
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... yes
checking for xsltParseStylesheetDoc() in -lxslt... yes
checking for exsltFuncRegister() in -lexslt... 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
make
compiling html_sax_parser_context.c
compiling xml_io.c
compiling xml_entity_reference.c
compiling xml_schema.c
compiling xml_element_content.c
compiling xml_reader.c
compiling xml_sax_push_parser.c
compiling xml_sax_parser.c
compiling xslt_stylesheet.c
compiling xml_element_decl.c
compiling xml_node.c
compiling xml_cdata.c
compiling xml_processing_instruction.c
compiling xml_entity_decl.c
compiling xml_attribute_decl.c
compiling xml_xpath_context.c
xml_xpath_context.c: In function ‘xpath_generic_exception_handler’:
xml_xpath_context.c:184:3: error: format not a string literal and no format arguments [-Werror=format-security]
cc1: some warnings being treated as errors
make: *** [xml_xpath_context.o] Error 1
Gem files will remain installed in /home/alex/.bundler/tmp/22194/gems/nokogiri-1.4.4 for inspection.
Results logged to /home/alex/.bundler/tmp/22194/gems/nokogiri-1.4.4/ext/nokogiri/gem_make.out
An error occurred while installing nokogiri (1.4.4), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.4.4'` succeeds before bundling.
I already installed libxslt-dev and libxml2-dev, but as you see, it didn't help.
How do I solve it?

I stumbled at this trying to install bigbluebutton on ubuntu 13.04
I solved it doing this trick to compile reverting the -Wformat-security gcc flag systemwide
Be careful doing the first rm. It can break your whole system!!
rm /usr/bin/gcc
nano /usr/bin/gcc
## contents of /usr/bin/gcc
#!/bin/sh
gcc-4.7 $* -Wno-format-security
## save and exit
chmod u+x /usr/bin/gcc
gem install nokogiri -v '1.4.4'

Is there a specific reason you need 1.4.4 instead of the latest 1.5.6? Otherwise I suggest upgrading.
The Nokogiri changelog shows they fixed this in 1.5.4:
Build support on hardened Debian systems that use
-Werror=format-security. #680.

#Confusion has the right idea.
Bundler is probably locked to nokogiri-1.4.4 in the Gemfile and/or Gemfile.lock. #Confusion's answer of running bundle update should allow your Ruby Bundler environment to use the successfully installed nokogiri-1.5.6.

Related

rmagick gem install problem undeclared identifier 'IsGrayImage' Macbook M1

I'm having problems installing Rmagick gem on my M1 Macbook. I installed the latest version of ImageMagick via brew arch -arm64 brew install imagemagick and tested it with the following commands:
magick logo: logo.gif
identify logo.gif
Once I confirmed it was working correctly I added the rmagick gem to my Gemfile.
Below is the output of the bundle install command.
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/user/.rvm/gems/ruby-2.7.2/gems/rmagick-4.2.2/ext/RMagick
/Users/user/.rvm/rubies/ruby-2.7.2/bin/ruby -I /Users/user/.rvm/rubies/ruby-2.7.2/lib/ruby/site_ruby/2.7.0 -r ./siteconf20210721-75512-tve65x.rb extconf.rb
checking for brew... yes
checking for Ruby version >= 2.3.0... yes
checking for pkg-config... yes
checking for forced use of ImageMagick 6... no
checking for outdated ImageMagick version (<= 6.7.7)... no
checking for gcc... yes
checking for __GNUC__... yes
checking for MagickCore/MagickCore.h... yes
checking for rb_gc_adjust_memory_usage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... yes
checking for posix_memalign() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... yes
checking for malloc_usable_size() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... no
checking for malloc_size() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... yes
checking for _aligned_msize() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... no
checking for GetImageChannelEntropy() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... no
checking for SetImageGray() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... no
checking for SetMagickAlignedMemoryMethods() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... no
checking for malloc.h... no
checking for malloc/malloc.h... yes
creating extconf.h
creating Makefile
======================================================================
Wed 21 Jul 21 07:25:56
This installation of RMagick 4.2.2 is configured for
Ruby 2.7.2 (x86_64-darwin20) and ImageMagick 7.1.0
======================================================================
Configured compile options: {:magick_version=>"7.1.0", :local_libs=>" -L/opt/homebrew/Cellar/imagemagick/7.1.0-4_1/lib -lMagickCore-7.Q16HDRI", :cflags=>" -Xpreprocessor -fopenmp
-DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/opt/homebrew/Cellar/imagemagick/7.1.0-4_1/include/ImageMagick-7 -std=gnu99", :cppflags=>" -Xpreprocessor -fopenmp
-DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/opt/homebrew/Cellar/imagemagick/7.1.0-4_1/include/ImageMagick-7", :ldflags=>"
-L/opt/homebrew/Cellar/imagemagick/7.1.0-4_1/lib -lMagickCore-7.Q16HDRI", :defs=>[], :config_h=>"Makefile"}
current directory: /Users/user/.rvm/gems/ruby-2.7.2/gems/rmagick-4.2.2/ext/RMagick
make DESTDIR\= clean
current directory: /Users/user/.rvm/gems/ruby-2.7.2/gems/rmagick-4.2.2/ext/RMagick
make DESTDIR\=
compiling rmagick.c
compiling rmdraw.c
compiling rmenum.c
compiling rmfill.c
compiling rmilist.c
compiling rmimage.c
rmimage.c:7552:32: error: use of undeclared identifier 'IsGrayImage'
return has_attribute(self, IsGrayImage);
^
1 error generated.
make: *** [Makefile:245: rmimage.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/user/.rvm/gems/ruby-2.7.2/gems/rmagick-4.2.2 for inspection.
Results logged to /Users/user/.rvm/gems/ruby-2.7.2/extensions/x86_64-darwin-20/2.7.0/rmagick-4.2.2/gem_make.out
An error occurred while installing rmagick (4.2.2), and Bundler cannot continue.
Make sure that `gem install rmagick -v '4.2.2' --source 'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
rmagick
Make sure your Ruby, rmagick and ImageMagick are all 64-bit or are all 32-bit. That was my problem on Windows 10 (see Github post you replied to).

gem install pg won't bundle

Trying to deploy Rails app onUbuntu 20 is impossible to install pg, and any attempt to bundle will incur in errors
$ gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /home/user/.rvm/gems/ruby-2.6.1/gems/pg-1.2.3/ext
/home/user/.rvm/rubies/ruby-2.6.1/bin/ruby -I /home/user/.rvm/rubies/ruby-2.6.1/lib/ruby/site_ruby/2.6.0 -r ./siteconf20210417-119158-37ke72.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... yes
checking for PQsetSingleRowMode()... yes
checking for PQconninfo()... yes
checking for PQsslAttribute()... yes
checking for PQresultVerboseErrorMessage()... yes
checking for PQencryptPasswordConn()... yes
checking for PQresultMemorySize()... yes
checking for timegm()... yes
checking for rb_gc_adjust_memory_usage()... yes
checking for unistd.h... yes
checking for inttypes.h... yes
checking for C99 variable length arrays... yes
creating extconf.h
creating Makefile
current directory: /home/user/.rvm/gems/ruby-2.6.1/gems/pg-1.2.3/ext
make "DESTDIR=" clean
current directory: /home/user/.rvm/gems/ruby-2.6.1/gems/pg-1.2.3/ext
make "DESTDIR="
compiling gvl_wrappers.c
compiling pg.c
compiling pg_binary_decoder.c
compiling pg_binary_encoder.c
compiling pg_coder.c
compiling pg_connection.c
compiling pg_copy_coder.c
compiling pg_errors.c
compiling pg_record_coder.c
compiling pg_result.c
compiling pg_text_decoder.c
compiling pg_text_encoder.c
compiling pg_tuple.c
compiling pg_type_map.c
compiling pg_type_map_all_strings.c
compiling pg_type_map_by_class.c
compiling pg_type_map_by_column.c
compiling pg_type_map_by_mri_type.c
compiling pg_type_map_by_oid.c
compiling pg_type_map_in_ruby.c
compiling pg_util.c
linking shared-object pg_ext.so
current directory: /home/user/.rvm/gems/ruby-2.6.1/gems/pg-1.2.3/ext
make "DESTDIR=" install
make: /usr/bin/mkdir: Command not found
make: *** [Makefile:201: .sitearchdir.time] Error 127
make install failed, exit code 2
Gem files will remain installed in /home/user/.rvm/gems/ruby-2.6.1/gems/pg-1.2.3 for inspection.
Results logged to /home/user/.rvm/gems/ruby-2.6.1/extensions/x86_64-linux/2.6.0/pg-1.2.3/gem_make.out
on bundle install nothing seem to work:
An error occurred while installing bcrypt (3.1.16), and Bundler cannot continue.
Make sure that gem install bcrypt -v '3.1.16' --source 'https://rubygems.org/' succeeds before bundling.
In Gemfile:
bcrypt
An error occurred while installing nio4r (2.5.7), and Bundler cannot continue.
Make sure that gem install nio4r -v '2.5.7' --source 'https://rubygems.org/' succeeds before bundling.
In Gemfile:
rails was resolved to 6.1.3.1, which depends on
actioncable was resolved to 6.1.3.1, which depends on
nio4r
An error occurred while installing racc (1.5.2), and Bundler cannot continue.
Make sure that gem install racc -v '1.5.2' --source 'https://rubygems.org/' succeeds before bundling.
Nothing seems to work and there is not useful information on how to solve problem
make: /usr/bin/mkdir: Command not found it's the reason.
Please write this command with sudo perm.
sudo ln -s $(which mkdir) /usr/bin/mkdir
And try again bundle.
This happens because you need install the following packages that the pg gem requires:
sudo apt install postgresql postgresql-contrib libpq-dev
Then configure postgres and verify is running.

noi4r gem install issues

In trying to install the nio4r gem. I tried
gem install nio4r -v '1.0.0'
The error that pops up is:
Building native extensions. This could take a while...
ERROR: Error installing nio4r:
ERROR: Failed to build gem native extension.
/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150406-11564-1qtifmf.rb extconf.rb
checking for rb_thread_blocking_region()... no
checking for sys/select.h... yes
checking for poll.h... yes
checking for sys/epoll.h... no
checking for sys/event.h... yes
checking for sys/queue.h... yes
checking for port.h... no
checking for sys/resource.h... yes
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling monitor.c
In file included from monitor.c:6:
In file included from ./nio4r.h:10:
/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/backward/rubyio.h:2:2: warning: use "ruby/io.h" instead of "rubyio.h" [-W#warnings]
warning use "ruby/io.h" instead of "rubyio.h"
...
What am I getting wrong? Is it an issue with my RVM?
With some basic updates, I was able to get it to work.
bundle update
and then
bundle
installs the gem.
Thanks to https://github.com/celluloid/nio4r/issues/46
Another approach would be to install a later version of ruby with RVM and do bundle again. Both works

Bundler won't install libxml-ruby (2.2.2) Rails

I'm trying to get set up with a somewhat outdated Rails app so I can try and update it a little but I can't seem to get bundle install working. It keeps telling me:
An error occurred while installing libxml-ruby (2.2.2), and Bundler cannot continue.
Make sure that `gem install libxml-ruby -v '2.2.2'` succeeds before bundling.
The entire error is:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/home/camillavk/.rvm/rubies/ruby-2.1.5/bin/ruby -r ./siteconf20150122-7039-3vyx6p.rb extconf.rb
extconf.rb:17:in `<main>': Use RbConfig instead of obsolete and deprecated Config.
extconf.rb:17:in `<main>': Use RbConfig instead of obsolete and deprecated Config.
checking for socket() in -lsocket... no
checking for gethostbyname() in -lnsl... yes
checking for atan() in -lm... yes
checking for inflate() in -lz... yes
checking for iconv_open() in -liconv... no
checking for libiconv_open() in -liconv... no
checking for libiconv_open() in -llibiconv... no
checking for iconv_open() in -llibiconv... no
checking for iconv_open() in -lc... yes
checking for xmlParseDoc() in -lxml2... yes
checking for libxml/xmlversion.h... no
checking for libxml/xmlversion.h in /opt/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... yes
creating extconf.h
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling ruby_xml_html_parser_options.c
compiling ruby_xml_cbg.c
compiling ruby_xml_html_parser.c
compiling ruby_xml_relaxng.c
compiling ruby_xml_schema.c
compiling ruby_xml_xpath_expression.c
compiling ruby_xml_parser.c
compiling ruby_xml_io.c
compiling ruby_xml_error.c
compiling ruby_xml_html_parser_context.c
ruby_xml_html_parser_context.c: In function ‘rxml_html_parser_context_options_set’:
ruby_xml_html_parser_context.c:307:7: warning: variable ‘result’ set but not used [-Wunused-but-set-variable]
int result;
^
compiling ruby_xml_node.c
ruby_xml_node.c: In function ‘rxml_node_to_s’:
ruby_xml_node.c:585:54: error: dereferencing pointer to incomplete type
result = rxml_new_cstr((const char*) output->conv->content, xencoding);
^
ruby_xml_node.c:587:56: error: dereferencing pointer to incomplete type
result = rxml_new_cstr((const char*) output->buffer->content, xencoding);
^
make: *** [ruby_xml_node.o] Error 1
make failed, exit code 2
Gem files will remain installed in /home/camillavk/.rvm/gems/ruby-2.1.5/gems/libxml-ruby-2.2.2 for inspection.
Results logged to /home/camillavk/.rvm/gems/ruby-2.1.5/extensions/x86_64-linux/2.1.0/libxml-ruby-2.2.2/gem_make.out
An error occurred while installing libxml-ruby (2.2.2), and Bundler cannot continue.
Make sure that `gem install libxml-ruby -v '2.2.2'` succeeds before bundling.
When I try and install libxml-ruby it says;
gem install libxml-ruby *[master][ruby-2.1.5]
Building native extensions. This could take a while...
Successfully installed libxml-ruby-2.8.0
1 gem installed
but the same error occurs again when I use bundle install...
When I try
gem install libxml-ruby -v '2.2.2'
I get this error:
Building native extensions. This could take a while...
ERROR: Error installing libxml-ruby:
ERROR: Failed to build gem native extension.
/home/camillavk/.rvm/rubies/ruby-2.1.5/bin/ruby -r ./siteconf20150122-7254-1rcd0x0.rb extconf.rb
extconf.rb:17:in `<main>': Use RbConfig instead of obsolete and deprecated Config.
extconf.rb:17:in `<main>': Use RbConfig instead of obsolete and deprecated Config.
checking for socket() in -lsocket... no
checking for gethostbyname() in -lnsl... yes
checking for atan() in -lm... yes
checking for inflate() in -lz... yes
checking for iconv_open() in -liconv... no
checking for libiconv_open() in -liconv... no
checking for libiconv_open() in -llibiconv... no
checking for iconv_open() in -llibiconv... no
checking for iconv_open() in -lc... yes
checking for xmlParseDoc() in -lxml2... yes
checking for libxml/xmlversion.h... no
checking for libxml/xmlversion.h in /opt/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... yes
creating extconf.h
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling ruby_xml_html_parser_options.c
compiling ruby_xml_cbg.c
compiling ruby_xml_html_parser.c
compiling ruby_xml_relaxng.c
compiling ruby_xml_schema.c
compiling ruby_xml_xpath_expression.c
compiling ruby_xml_parser.c
compiling ruby_xml_io.c
compiling ruby_xml_error.c
compiling ruby_xml_html_parser_context.c
ruby_xml_html_parser_context.c: In function ‘rxml_html_parser_context_options_set’:
ruby_xml_html_parser_context.c:307:7: warning: variable ‘result’ set but not used [-Wunused-but-set-variable]
int result;
^
compiling ruby_xml_node.c
ruby_xml_node.c: In function ‘rxml_node_to_s’:
ruby_xml_node.c:585:54: error: dereferencing pointer to incomplete type
result = rxml_new_cstr((const char*) output->conv->content, xencoding);
^
ruby_xml_node.c:587:56: error: dereferencing pointer to incomplete type
result = rxml_new_cstr((const char*) output->buffer->content, xencoding);
^
make: *** [ruby_xml_node.o] Error 1
make failed, exit code 2
Gem files will remain installed in /home/camillavk/.rvm/gems/ruby-2.1.5/gems/libxml-ruby-2.2.2 for inspection.
Results logged to /home/camillavk/.rvm/gems/ruby-2.1.5/extensions/x86_64-linux/2.1.0/libxml-ruby-2.2.2/gem_make.out
I'm running this on linux -> does anyone have any idea how I can get around this or fix it?
Thanks

Error installing Nokogiri when using "bundle install"

When I run bundle install it stops with:
Installing nokogiri (1.4.3.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
I tried installing it manually using "Installing Nokogiri" but this did work out in my favour.
Do I need to change something?
/usr/bin/ruby1.9.1 extconf.rb'
extconf.rb:10: Use RbConfig instead of obsolete and deprecated Config.
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for xmlParseDoc() in -lxml2... yes
checking for xsltParseStylesheetDoc() in -lxslt... yes
checking for exsltFuncRegister() in -lexslt... 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
Or this:
make
compiling xml_dtd.c
compiling xml_entity_reference.c
compiling xml_sax_parser_context.c
compiling xml_attribute_decl.c
compiling xml_schema.c
compiling xml_processing_instruction.c
compiling xml_cdata.c
compiling xml_xpath_context.c
xml_xpath_context.c: In function ‘xpath_generic_exception_handler’:
xml_xpath_context.c:154:3: error: format not a string literal and no format arguments [- Werror=format-security]
cc1: some warnings being treated as errors
make: *** [xml_xpath_context.o] Error 1
Gem files will remain installed in /home/virinchy/.bundler/tmp/10048/gems/nokogiri- 1.4.3.1 for inspection.
Results logged to /home/virinchy/.bundler/tmp/10048/gems/nokogiri- 1.4.3.1/ext/nokogiri/gem_make.out
An error occured while installing nokogiri (1.4.3.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.4.3.1'` succeeds before bundling.'
First, Nokogiri 1.4.3.1 is almost three years old. You should upgrade.
Second, please see https://github.com/sparklemotion/nokogiri/issues/680 for details around how Debian hardened the gcc compiler. You will need to use either an older version of debian or a newer version of Nokogiri.

Resources