简体   繁体   English

安装Nokogiri gem时出错

[英]Error installing Nokogiri gem

I'm having problems installing the nokogiri gem on Mac OS 10.9.2. 我在Mac OS 10.9.2上安装nokogiri gem时遇到问题。 I've tried using brew install libxml to resolve any dependencies, but it didn't seem to work. 我尝试使用brew install libxml来解决任何依赖关系,但是它似乎没有用。 I'm not sure how to resolve the linking issues it seems to be getting with clang. 我不确定如何解决clang似乎遇到的链接问题。

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

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb 
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-apple-darwin13.1.0/ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... OK
Running 'compile' for libxml2 2.8.0... OK
Running 'install' for libxml2 2.8.0... OK
Activating libxml2 2.8.0 (from /Users/***/.bundler/tmp/63074/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin13.1.0/libxml2/2.8.0)...
Extracting libxslt-1.1.26.tar.gz into tmp/x86_64-apple-darwin13.1.0/ports/libxslt/1.1.26... OK
Running 'configure' for libxslt 1.1.26... OK
Running 'compile' for libxslt 1.1.26... OK
Running 'install' for libxslt 1.1.26... OK
Activating libxslt 1.1.26 (from /Users/***/.bundler/tmp/63074/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin13.1.0/libxslt/1.1.26)...
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... no
checking for iconv_open() in -liconv... yes
checking for xmlParseDoc() in -lxml2... yes
checking for xsltParseStylesheetDoc() in -lxslt... yes
checking for exsltFuncRegister() in -lexslt... 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

make "DESTDIR=" clean

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
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
compiling xml_libxml2_hacks.c
compiling xml_namespace.c
compiling xml_node.c
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
linking shared-object nokogiri/nokogiri.bundle
clang: error: unknown argument: '-multiply_definedsuppress' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
make: *** [nokogiri.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/***/.bundler/tmp/63074/gems/nokogiri-1.6.1 for inspection.
Results logged to /Users/***/.bundler/tmp/63074/extensions/universal-darwin-13/2.0.0/nokogiri-1.6.1/gem_make.out
An error occurred while installing nokogiri (1.6.1), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.6.1'` succeeds before bundling.

Here's the extconf.rb file 这是extconf.rb文件

ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/

# :stopdoc:

require 'mkmf'

RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']

ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
LIBDIR = RbConfig::CONFIG['libdir']
@libdir_basename = "lib" # shrug, ruby 2.0 won't work for me.
INCLUDEDIR = RbConfig::CONFIG['includedir']

if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
  $LIBRUBYARG_STATIC.gsub!(/-static/, '')
end

$CFLAGS << " #{ENV["CFLAGS"]}"
$LIBS << " #{ENV["LIBS"]}"

windows_p = RbConfig::CONFIG['target_os'] == 'mingw32' || RbConfig::CONFIG['target_os'] =~ /mswin/

if windows_p
  $CFLAGS << " -DXP_WIN -DXP_WIN32 -DUSE_INCLUDED_VASPRINTF"
elsif RbConfig::CONFIG['target_os'] =~ /solaris/
  $CFLAGS << " -DUSE_INCLUDED_VASPRINTF"
else
  $CFLAGS << " -g -DXP_UNIX"
end

if RbConfig::MAKEFILE_CONFIG['CC'] =~ /mingw/
  $CFLAGS << " -DIN_LIBXML"
  $LIBS << " -lz" # TODO why is this necessary?
end

if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc/
  $CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
  $CFLAGS << " -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline"
end

if windows_p
  # I'm cross compiling!
  HEADER_DIRS = [INCLUDEDIR]
  LIB_DIRS = [LIBDIR]
  XML2_HEADER_DIRS = [File.join(INCLUDEDIR, "libxml2"), INCLUDEDIR]

else
  if ENV['NOKOGIRI_USE_SYSTEM_LIBRARIES']
    HEADER_DIRS = [
      # First search /opt/local for macports
      '/opt/local/include',

      # Then search /usr/local for people that installed from source
      '/usr/local/include',

      # Check the ruby install locations
      INCLUDEDIR,

      # Finally fall back to /usr
      '/usr/include',
      '/usr/include/libxml2',
    ]

    LIB_DIRS = [
      # First search /opt/local for macports
      '/opt/local/lib',

      # Then search /usr/local for people that installed from source
      '/usr/local/lib',

      # Check the ruby install locations
      LIBDIR,

      # Finally fall back to /usr
      '/usr/lib',
    ]

    XML2_HEADER_DIRS = [
      '/opt/local/include/libxml2',
      '/usr/local/include/libxml2',
      File.join(INCLUDEDIR, "libxml2")
    ] + HEADER_DIRS

    # If the user has homebrew installed, use the libxml2 inside homebrew
    brew_prefix = `brew --prefix libxml2 2> /dev/null`.chomp
    unless brew_prefix.empty?
      LIB_DIRS.unshift File.join(brew_prefix, 'lib')
      XML2_HEADER_DIRS.unshift File.join(brew_prefix, 'include/libxml2')
    end

  else
    require 'mini_portile'
    require 'yaml'

    common_recipe = lambda do |recipe|
      recipe.target = File.join(ROOT, "ports")
      recipe.files = ["ftp://ftp.xmlsoft.org/libxml2/#{recipe.name}-#{recipe.version}.tar.gz"]

      checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
      unless File.exist?(checkpoint)
        recipe.cook
        FileUtils.touch checkpoint
      end
      recipe.activate
    end

    dependencies = YAML.load_file(File.join(ROOT, "dependencies.yml"))

    libxml2_recipe = MiniPortile.new("libxml2", dependencies["libxml2"]).tap do |recipe|
      recipe.configure_options = [
        "--enable-shared",
        "--disable-static",
        "--without-python",
        "--without-readline",
        "--with-c14n",
        "--with-debug",
        "--with-threads"
      ]
      common_recipe.call recipe
    end

    libxslt_recipe = MiniPortile.new("libxslt", dependencies["libxslt"]).tap do |recipe|
      recipe.configure_options = [
        "--enable-shared",
        "--disable-static",
        "--without-python",
        "--without-crypto",
        "--with-debug",
        "--with-libxml-prefix=#{libxml2_recipe.path}"
      ]
      common_recipe.call recipe
    end

    $LDFLAGS << " -Wl,-rpath,#{libxml2_recipe.path}/lib"
    $LDFLAGS << " -Wl,-rpath,#{libxslt_recipe.path}/lib"

    $CFLAGS << " -DNOKOGIRI_USE_PACKAGED_LIBRARIES -DNOKOGIRI_LIBXML2_PATH='\"#{libxml2_recipe.path}\"' -DNOKOGIRI_LIBXSLT_PATH='\"#{libxslt_recipe.path}\"'"

    HEADER_DIRS = [libxml2_recipe, libxslt_recipe].map { |f| File.join(f.path, "include") }
    LIB_DIRS = [libxml2_recipe, libxslt_recipe].map { |f| File.join(f.path, "lib") }
    XML2_HEADER_DIRS = HEADER_DIRS + [File.join(libxml2_recipe.path, "include", "libxml2")]
  end
end

dir_config('zlib', HEADER_DIRS, LIB_DIRS)
dir_config('iconv', HEADER_DIRS, LIB_DIRS)
dir_config('xml2', XML2_HEADER_DIRS, LIB_DIRS)
dir_config('xslt', HEADER_DIRS, LIB_DIRS)

def asplode(lib)
  abort "-----\n#{lib} is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.\n-----"
end

pkg_config('libxslt')
pkg_config('libxml-2.0')
pkg_config('libiconv')

def have_iconv?
  %w{ iconv_open libiconv_open }.any? do |method|
    have_func(method, 'iconv.h') or
      have_library('iconv', method, 'iconv.h') or
      find_library('iconv', method, 'iconv.h')
  end
end

asplode "libxml2"  unless find_header('libxml/parser.h')
asplode "libxslt"  unless find_header('libxslt/xslt.h')
asplode "libexslt" unless find_header('libexslt/exslt.h')
asplode "libiconv" unless have_iconv?
asplode "libxml2"  unless find_library("xml2", 'xmlParseDoc')
asplode "libxslt"  unless find_library("xslt", 'xsltParseStylesheetDoc')
asplode "libexslt" unless find_library("exslt", 'exsltFuncRegister')

unless have_func('xmlHasFeature')
  abort "-----\nThe function 'xmlHasFeature' is missing from your installation of libxml2.  Likely this means that your installed version of libxml2 is old enough that nokogiri will not work well.  To get around this problem, please upgrade your installation of libxml2.

Please visit http://nokogiri.org/tutorials/installing_nokogiri.html for more help!"
end

have_func 'xmlFirstElementChild'
have_func('xmlRelaxNGSetParserStructuredErrors')
have_func('xmlRelaxNGSetParserStructuredErrors')
have_func('xmlRelaxNGSetValidStructuredErrors')
have_func('xmlSchemaSetValidStructuredErrors')
have_func('xmlSchemaSetParserStructuredErrors')

if ENV['CPUPROFILE']
  unless find_library('profiler', 'ProfilerEnable', *LIB_DIRS)
    abort "google performance tools are not installed"
  end
end

create_makefile('nokogiri/nokogiri')

# :startdoc:

这是唯一对我有用的命令:

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri

I fixed the problem by first using brew install libxml2 libxslt . 我通过首先使用brew install libxml2 libxslt解决了该问题。 I then had to download the old xcode-select developer tools from late October found here https://developer.apple.com/downloads/index.action# 然后,我不得不从10月下旬开始下载旧的xcode-select开发人员工具, 网址为https://developer.apple.com/downloads/index.action#

After that, running sudo gem install nokogiri finally worked. 之后,运行sudo gem install nokogiri终于成功了。

After upgrading OS X from Mountain Lion to Maverick, encountered errors installing nokogiri. 将OS X从Mountain Lion升级到Maverick后,在安装nokogiri时遇到错误。 Resolved the error by reinstalling the command line tools. 通过重新安装命令行工具解决了该错误。

  • brew doctor 酿造医生
  • xcode-select --install xcode-select-安装

My env: Ruby 2.1, rvm, Rails 4.1.1 我的环境:Ruby 2.1,rvm,Rails 4.1.1

You can go into the Makefile in $HOME/.bundler/tmp/63074/gems/nokogiri-1.6.1 and edit the switches as a temporary fix. 您可以进入$HOME/.bundler/tmp/63074/gems/nokogiri-1.6.1的Makefile并将编辑开关作为临时修订。 It did succeed on my system, FWIW. 它确实在我的系统FWIW上成功。

使用来自http://www.installrails.com/steps/install_rails的 gem install rails --no-ri --no-rdoc对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用“sudo gem install nokogiri”在mac上安装nokogiri时出错 - Error when installing nokogiri on mac with“sudo gem install nokogiri” 在Windows上安装Nokogiri gem - Installing Nokogiri gem on windows 错误:安装nokogiri时出错:错误:无法构建gem本机扩展 - ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension 安装nokogiri(1.6.7.2)时出现捆绑安装错误。 宝石安装但不适用于Rails应用 - Bundle install error installing nokogiri (1.6.7.2). Gem installs but not for rails app nokogiri gem 安装错误 - nokogiri gem installation error 捆绑软件安装失败(错误:安装nokogiri时出错:错误:无法构建gem本机扩展) - bundle install failed (ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension) Nokogiri宝石安装错误与狂欢 - Nokogiri gem installation error with spree 错误:安装nokogiri -v&#39;1.5.6&#39;时执行gem…(Errno :: EACCES)时,权限被拒绝 - ERROR: While executing gem … (Errno::EACCES) while installing nokogiri -v '1.5.6' Permission denied 安装 nokogiri 时出错:无法构建 gem 本机扩展并且缺少 libiconv (OSX) - Error installing nokogiri: Failed to build gem native extension & libiconv is missing (OSX) nokogiri - 错误:无法构建 gem 原生扩展 - nokogiri - ERROR: Failed to build gem native extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM