![](/img/trans.png)
[英]Error when installing nokogiri on mac with“sudo gem install nokogiri”
[英]Error installing Nokogiri gem
我在Mac OS 10.9.2上安裝nokogiri gem時遇到問題。 我嘗試使用brew install libxml來解決任何依賴關系,但是它似乎沒有用。 我不確定如何解決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.
這是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
我通過首先使用brew install libxml2 libxslt
解決了該問題。 然后,我不得不從10月下旬開始下載舊的xcode-select開發人員工具, 網址為https://developer.apple.com/downloads/index.action#
之后,運行sudo gem install nokogiri
終於成功了。
將OS X從Mountain Lion升級到Maverick后,在安裝nokogiri時遇到錯誤。 通過重新安裝命令行工具解決了該錯誤。
我的環境:Ruby 2.1,rvm,Rails 4.1.1
您可以進入$HOME/.bundler/tmp/63074/gems/nokogiri-1.6.1
的Makefile並將編輯開關作為臨時修訂。 它確實在我的系統FWIW上成功。
使用來自http://www.installrails.com/steps/install_rails的 gem install rails --no-ri --no-rdoc對我有用 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.