CPride
CPride

Reputation: 105

Error installing Nokogiri gem

I'm having problems installing the nokogiri gem on Mac OS 10.9.2. I've tried using brew install libxml to resolve any dependencies, but it didn't seem to work. I'm not sure how to resolve the linking issues it seems to be getting with 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

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:

Upvotes: 3

Views: 3622

Answers (5)

JerryZhou
JerryZhou

Reputation: 5206

use gem install rails --no-ri --no-rdoc from http://www.installrails.com/steps/install_rails works for me.

Upvotes: 0

wh1tney
wh1tney

Reputation: 1237

This was the only command that did the trick for me:

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

Upvotes: 4

user553620
user553620

Reputation: 775

After upgrading OS X from Mountain Lion to Maverick, encountered errors installing nokogiri. Resolved the error by reinstalling the command line tools.

  • brew doctor
  • xcode-select --install

My env: Ruby 2.1, rvm, Rails 4.1.1

Upvotes: 1

CPride
CPride

Reputation: 105

I fixed the problem by first using 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#

After that, running sudo gem install nokogiri finally worked.

Upvotes: 1

hd1
hd1

Reputation: 34677

You can go into the Makefile in $HOME/.bundler/tmp/63074/gems/nokogiri-1.6.1 and edit the switches as a temporary fix. It did succeed on my system, FWIW.

Upvotes: 0

Related Questions