nokogiri 未安装在 ruby 2.7.1 centos 7.2 中

nokogiri not installing in ruby 2.7.1 centos 7.2

Getting below error when installing nokogiri i tried

install -y make gcc rpm-build ruby-devel zlib-devel
gem 安装 nokogiri

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

    current directory: /usr/local/rvm/gems/ruby-2.7.1/gems/nokogiri-1.10.10/ext/nokogiri
/usr/local/rvm/rubies/ruby-2.7.1/bin/ruby -I /usr/local/rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0 -r ./siteconf20200716-18065-1jmltdp.rb extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
Using mini_portile version 2.4.0
checking for gzdopen() in -lz... yes
checking for iconv... yes
************************************************************************
IMPORTANT NOTICE:

Building Nokogiri with a packaged version of libxml2-2.9.10
with the following patches applied:
        - 0001-Revert-Do-not-URI-escape-in-server-side-includes.patch
        - 0002-Remove-script-macro-support.patch
        - 0003-Update-entities-to-remove-handling-of-ssi.patch
        - 0004-libxml2.la-is-in-top_builddir.patch
        - 0005-Fix-infinite-loop-in-xmlStringLenDecodeEntities.patch

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.10.tar.gz into tmp/x86_64-pc-linux-gnu/ports/libxml2/2.9.10... OK
Running patch with /usr/local/rvm/gems/ruby-2.7.1/gems/nokogiri-1.10.10/patches/libxml2/0001-Revert-Do-not-URI-escape-in-server-side-includes.patch... OK
Running patch with /usr/local/rvm/gems/ruby-2.7.1/gems/nokogiri-1.10.10/patches/libxml2/0002-Remove-script-macro-support.patch... OK
Running patch with /usr/local/rvm/gems/ruby-2.7.1/gems/nokogiri-1.10.10/patches/libxml2/0003-Update-entities-to-remove-handling-of-ssi.patch... OK
Running patch with /usr/local/rvm/gems/ruby-2.7.1/gems/nokogiri-1.10.10/patches/libxml2/0004-libxml2.la-is-in-top_builddir.patch... OK
Running patch with /usr/local/rvm/gems/ruby-2.7.1/gems/nokogiri-1.10.10/patches/libxml2/0005-Fix-infinite-loop-in-xmlStringLenDecodeEntities.patch... OK
Running 'configure' for libxml2 2.9.10... OK
Running 'compile' for libxml2 2.9.10... OK
Running 'install' for libxml2 2.9.10... OK
Activating libxml2 2.9.10 (from /usr/local/rvm/gems/ruby-2.7.1/gems/nokogiri-1.10.10/ports/x86_64-pc-linux-gnu/libxml2/2.9.10)...
************************************************************************
IMPORTANT NOTICE:

Building Nokogiri with a packaged version of libxslt-1.1.34.

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
************************************************************************
Extracting libxslt-1.1.34.tar.gz into tmp/x86_64-pc-linux-gnu/ports/libxslt/1.1.34... OK
Running 'configure' for libxslt 1.1.34... OK
Running 'compile' for libxslt 1.1.34... OK
Running 'install' for libxslt 1.1.34... OK
Activating libxslt 1.1.34 (from /usr/local/rvm/gems/ruby-2.7.1/gems/nokogiri-1.10.10/ports/x86_64-pc-linux-gnu/libxslt/1.1.34)...
checking for -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

current directory: /usr/local/rvm/gems/ruby-2.7.1/gems/nokogiri-1.10.10/ext/nokogiri
make "DESTDIR=" clean

current directory: /usr/local/rvm/gems/ruby-2.7.1/gems/nokogiri-1.10.10/ext/nokogiri
make "DESTDIR="
compiling html_document.c
compiling html_element_description.c
compiling html_entity_lookup.c
compiling html_sax_parser_context.c
compiling html_sax_push_parser.c
compiling nokogiri.c
compiling xml_attr.c
compiling xml_attribute_decl.c
compiling xml_cdata.c
compiling xml_comment.c
compiling xml_document.c
xml_document.c: In function ‘dealloc’:
xml_document.c:49:3: warning: passing argument 2 of ‘rb_st_foreach’ from incompatible pointer type [enabled by default]
   st_foreach(node_hash, dealloc_node_i, (st_data_t)doc);
   ^
In file included from /usr/local/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/ruby/intern.h:39:0,
                 from /usr/local/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/ruby/ruby.h:2148,
                 from /usr/local/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/ruby.h:33,
                 from ./nokogiri.h:33,
                 from ./xml_document.h:4,
                 from xml_document.c:1:
/usr/local/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/ruby/st.h:141:5: note: expected ‘int (*)(st_data_t,  st_data_t,  st_data_t)’ but argument is of type ‘int (*)(struct xmlNode *, struct xmlNode *, struct xmlDoc *)’
 int rb_st_foreach(st_table *, st_foreach_callback_func *, st_data_t);
     ^
xml_document.c: At top level:
cc1: warning: unrecognized command line option "-Wno-tautological-compare" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-self-assign" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-cast-function-type" [enabled by default]
compiling xml_document_fragment.c
compiling xml_dtd.c
compiling xml_element_content.c
compiling xml_element_decl.c
compiling xml_encoding_handler.c
compiling xml_entity_decl.c
compiling xml_entity_reference.c
compiling xml_io.c
xml_io.c: In function ‘io_read_callback’:
xml_io.c:20:3: warning: passing argument 1 of ‘rb_rescue’ from incompatible pointer type [enabled by default]
   string = rb_rescue(read_check, (VALUE)args, read_failed, 0);
   ^
In file included from /usr/local/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/ruby.h:33:0,
                 from ./nokogiri.h:33,
                 from ./xml_io.h:4,
                 from xml_io.c:1:
**/usr/local/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/ruby/ruby.h:1987:7: note: expected ‘VALUE (*)(VALUE)’ but argument is of type ‘VALUE (*)(VALUE *)’
 VALUE rb_rescue(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE);**
       ^
*xml_io.c:20:3: warning: passing argument 3 of ‘rb_rescue’ from incompatible pointer type [enabled by default]
   string = rb_rescue(read_check, (VALUE)args, read_failed, 0);
   ^*
In file included from /usr/local/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/ruby.h:33:0,
                 from ./nokogiri.h:33,
                 from ./xml_io.h:4,
                 from xml_io.c:1:
/usr/local/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/ruby/ruby.h:1987:7: note: expected ‘VALUE (*)(VALUE,  VALUE)’ but argument is of type ‘VALUE (*)(void)’
 VALUE rb_rescue(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE);
       ^

xml_io.c: In function ‘io_write_callback’: xml_io.c:47:3: warning: passing argument 1 of ‘rb_rescue’ from incompatible pointer type [enabled by default] size = rb_rescue(write_check, (VALUE)args, write_failed, 0); ^ In file included from /usr/local/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/ruby.h:33:0, from ./nokogiri.h:33, from ./xml_io.h:4, from xml_io.c:1: /usr/local/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/ruby/ruby.h:1987:7: note: expected ‘VALUE ()(VALUE)’ but argument is of type ‘VALUE ()(VALUE )’ VALUE rb_rescue(VALUE()(VALUE),VALUE,VALUE()(VALUE,VALUE),VALUE); ^ xml_io.c:47:3: warning: passing argument 3 of ‘rb_rescue’ from incompatible pointer type [enabled by default] size = rb_rescue(write_check, (VALUE)args, write_failed, 0); ^ In file included from /usr/local/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/ruby.h:33:0, from ./nokogiri.h:33, from ./xml_io.h:4, from xml_io.c:1: /usr/local/rvm/rubies/ruby-2.7.1/include/ruby-2.7.0/ruby/ruby.h:1987:7: note: expected ‘VALUE ()(VALUE, VALUE)’ but argument is of type ‘VALUE ()(void)’ VALUE rb_rescue(VALUE()(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE);

       ^
***xml_io.c: At top level:
cc1: warning: unrecognized command line option "-Wno-tautological-compare" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-self-assign" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-cast-function-type" [enabled by default]
compiling xml_libxml2_hacks.c
compiling xml_namespace.c
compiling xml_node.c
xml_node.c: In function ‘reparent_node_with’:
xml_node.c:304:7: warning: passing argument 1 of ‘xmlFree’ discards ‘const’ qualifier from pointer target type [enabled by default]
       xmlFree(reparentee->ns->prefix);
       ^***
xml_node.c:304:7: note: expected ‘void *’ but argument is of type ‘const xmlChar *’
xml_node.c: At top level:
cc1: warning: unrecognized command line option "-Wno-tautological-compare" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-self-assign" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-cast-function-type" [enabled by default]
compiling xml_node_set.c
compiling xml_processing_instruction.c
compiling xml_reader.c
compiling xml_relax_ng.c
compiling xml_sax_parser.c
compiling xml_sax_parser_context.c
compiling xml_sax_push_parser.c
compiling xml_schema.c
compiling xml_syntax_error.c
compiling xml_text.c
compiling xml_xpath_context.c
compiling xslt_stylesheet.c
xslt_stylesheet.c:112:13: warning: ‘swallow_superfluous_xml_errors’ defined but not used [-Wunused-function]
 static void swallow_superfluous_xml_errors(void * userdata, xmlErrorPtr error, ...)
             ^
cc1: warning: unrecognized command line option "-Wno-tautological-compare" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-self-assign" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-cast-function-type" [enabled by default]
linking shared-object nokogiri/nokogiri.so
/usr/bin/ld: unrecognized option '--compress-debug-sections=zlib'
/usr/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status
make: *** [nokogiri.so] Error 1

make failed, exit code 2

我的 Centos 版本是 7.6,所有为 nokogiri 提供的解决方案都不起作用。最后我将 centos 更新到 7.8 并且它有效。我也在其他服务器上尝试过 centos 7.7 版本,它也适用于 7.7。

我遇到了完全相同的问题。 看来真正的错误是

/usr/bin/ld: unrecognized option '--compress-debug-sections=zlib'

标志“--compress-debug-sections=zlib”在文件 /usr/local/rvm/gems/ruby-2.7.0/gems/nokogiri-1.10.10/ext/nokogiri/Makefile 中定义。 此 makefile 由 mkmf.rb 创建,标志的默认值在此文件中 /usr/local/rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/x86_64-linux/rbconfig.rb

CONFIG["DLDFLAGS"] = "-Wl,--compress-debug-sections=zlib"

我把这行改成

CONFIG["DLDFLAGS"] = ""

gem 安装 nokogiri 效果很好

但我不确定标志“--compress-debug-sections=zlib”的确切功能以及删除它后会发生什么

我的centos版本比较旧,/usr/bin/ldbinutils的一部分,所以我的建议

$ sudo yum update binutils

帮助了我(而不是完整的 OS 更新)

出现此错误是因为 Centos 7.4 上的默认链接器不支持该选项 --compress-debug-sections=zlibCentos 7.8 似乎解决了这个问题。

但如果您无法切换到 Centos 7.8,黄金链接器 (ld.gold) 支持该选项。

要启用此功能,您可以通过执行类似

的操作来覆盖链接器
ln -s /bin/ld.gold ~/bin/ld; PATH=~/bin:$PATH

然后运行需要的命令