Installing nokogiri - Failed to build gem native e

2019-04-15 05:21发布

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?

3条回答
乱世女痞
2楼-- · 2019-04-15 05:43

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'
查看更多
仙女界的扛把子
3楼-- · 2019-04-15 06:00

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.

查看更多
唯我独甜
4楼-- · 2019-04-15 06:03

@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.

查看更多
登录 后发表回答