Skip to content

Installing Nokogiri 1.6.2 fails on Mac with Xcode 5.1 #1101

Closed
mattneub opened this Issue May 13, 2014 · 20 comments

5 participants

@mattneub

As is well known, Xcode 5.1 includes a version of clang that is much pickier than previous versions. This affects Nokogiri:

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

By the way, preceding that there are also some warnings, but they are not fatal. I mention them here just in case it might be possible to fix them:

compiling xml_node.c
xml_node.c:17:14: warning: incompatible pointer types initializing 'xmlNodePtr' (aka 'struct _xmlNode *') with an expression of type 'struct _xmlDoc *' [-Wincompatible-pointer-types]
  xmlNodePtr doc = node->doc;
             ^     ~~~~~~~~~
xml_node.c:168:15: warning: 14 enumeration values not handled in switch: 'XML_ATTRIBUTE_NODE', 'XML_ENTITY_NODE', 'XML_DOCUMENT_NODE'... [-Wswitch]
      switch (reparentee->type) {
              ^
xml_node.c:186:15: warning: 15 enumeration values not handled in switch: 'XML_ATTRIBUTE_NODE', 'XML_ENTITY_NODE', 'XML_DOCUMENT_NODE'... [-Wswitch]
      switch (reparentee->type) {
              ^
xml_node.c:197:15: warning: 19 enumeration values not handled in switch: 'XML_ELEMENT_NODE', 'XML_ATTRIBUTE_NODE', 'XML_CDATA_SECTION_NODE'... [-Wswitch]
      switch (reparentee->type) {
              ^
xml_node.c:165:13: warning: 14 enumeration values not handled in switch: 'XML_CDATA_SECTION_NODE', 'XML_ENTITY_NODE', 'XML_PI_NODE'... [-Wswitch]
    switch (parent->type) {
            ^
5 warnings generated.

I was able to work around this by temporarily reverting to Xcode 5.0.2 (installation succeeds with no warnings), but that is not a viable long-term solution.

@zenspider

This is a problem with the stock ruby rbconfig.rb file. I removed it from mine and things are MOSTLY building fine:

--- /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin13/rbconfig.rb    2014-04-22 22:27:52.000000000 -0700
+++ /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin13/rbconfig.rb~   2013-10-30 23:18:46.000000000 -0700
@@ -15,7 +15,7 @@
   CONFIG["MAJOR"] = "2"
   CONFIG["MINOR"] = "0"
   CONFIG["TEENY"] = "0"
-  CONFIG["PATCHLEVEL"] = "451"
+  CONFIG["PATCHLEVEL"] = "247"
   CONFIG["INSTALL"] = '/usr/bin/install -c'
   CONFIG["EXEEXT"] = ""
   CONFIG["prefix"] = (TOPDIR || DESTDIR + "/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr")
@@ -37,7 +37,7 @@
   CONFIG["rubyhdrdir"] = "$(includedir)/$(RUBY_VERSION_NAME)"
   CONFIG["UNIVERSAL_INTS"] = "'long long' long int short"
   CONFIG["UNIVERSAL_ARCHNAMES"] = universal
-  CONFIG["configure_args"] = " '--prefix=/usr' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-dependency-tracking' '--prefix=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr' '--sysconfdir=/Library/Ruby/Site' '--with-sitedir=/Library/Ruby/Site' '--enable-shared' '--with-arch=x86_64,i386' '--with-bundled-md5' '--with-bundled-sha1' '--with-bundled-sha2' '--with-bundled-rmd160' 'ac_cv_func_getcontext=no' 'ac_cv_func_setcontext=no' 'ac_cv_c_compiler_gnu=no' 'rb_cv_pri_prefix_long_long=ll' 'CC=xcrun clang' 'CFLAGS=-arch x86_64 -arch i386 -g -Os -pipe ' 'LDFLAGS=-arch x86_64 -arch i386            ' 'CXX=xcrun clang++' 'CXXFLAGS=-arch x86_64 -arch i386 -g -Os -pipe '"
+  CONFIG["configure_args"] = " '--prefix=/usr' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-dependency-tracking' '--prefix=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr' '--sysconfdir=/Library/Ruby/Site' '--with-sitedir=/Library/Ruby/Site' '--enable-shared' '--with-arch=x86_64,i386' 'ac_cv_func_getcontext=no' 'ac_cv_func_setcontext=no' 'ac_cv_c_compiler_gnu=no' 'rb_cv_pri_prefix_long_long=ll' 'CC=xcrun clang' 'CFLAGS=#{arch_flag} -g -Os -pipe ' 'LDFLAGS=#{arch_flag} ' 'CXX=xcrun clang++' 'CXXFLAGS=#{arch_flag} -g -Os -pipe '"
   CONFIG["vendorarchdir"] = "$(vendorlibdir)/$(sitearch)"
   CONFIG["vendorlibdir"] = "$(vendordir)/$(ruby_version)"
   CONFIG["vendordir"] = "$(rubylibprefix)/vendor_ruby"
@@ -71,7 +71,7 @@
   CONFIG["DLDLIBS"] = ""
   CONFIG["SOLIBS"] = ""
   CONFIG["LIBRUBYARG_SHARED"] = "-l$(RUBY_SO_NAME)"
-  CONFIG["LIBRUBYARG_STATIC"] = "-l$(RUBY_SO_NAME)-static"
+  CONFIG["LIBRUBYARG_STATIC"] = "-l$(RUBY_SO_NAME)"
   CONFIG["LIBRUBYARG"] = "$(LIBRUBYARG_SHARED)"
   CONFIG["LIBRUBY"] = "$(LIBRUBY_SO)"
   CONFIG["LIBRUBY_ALIASES"] = "lib$(RUBY_BASE_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_INSTALL_NAME).dylib"
@@ -79,7 +79,7 @@
   CONFIG["LIBRUBY_A"] = "lib$(RUBY_SO_NAME)-static.a"
   CONFIG["RUBYW_INSTALL_NAME"] = ""
   CONFIG["rubyw_install_name"] = ""
-  CONFIG["LIBRUBY_DLDFLAGS"] = "-Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -install_name $(libdir)/$(LIBRUBY_SO) -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(ruby_version)  $(XLDFLAGS)"
+  CONFIG["LIBRUBY_DLDFLAGS"] = "-undefineddynamic_lookup -multiply_definedsuppress -install_name $(libdir)/$(LIBRUBY_SO) -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(ruby_version)  $(XLDFLAGS)"
   CONFIG["LIBRUBY_LDSHARED"] = "$(CC) -dynamiclib"
   CONFIG["EXTDLDFLAGS"] = ""
   CONFIG["EXTLDFLAGS"] = ""
@@ -102,7 +102,6 @@
   CONFIG["ARCHFILE"] = ""
   CONFIG["LIBRUBY_RELATIVE"] = "no"
   CONFIG["EXTOUT"] = ".ext"
-  CONFIG["RUNRUBY_COMMAND"] = "$(MINIRUBY) $(srcdir)/tool/runruby.rb --extout=$(EXTOUT) $(RUNRUBYOPT)"
   CONFIG["PREP"] = "miniruby$(EXEEXT)"
   CONFIG["BTESTRUBY"] = "$(MINIRUBY)"
   CONFIG["CROSS_COMPILING"] = "no"
@@ -122,8 +121,8 @@
   CONFIG["LDSHARED"] = "$(CC) -dynamic -bundle"
   CONFIG["CCDLFLAGS"] = ""
   CONFIG["STATIC"] = ""
-  CONFIG["ARCH_FLAG"] = arch_flag || " -arch x86_64 -arch i386"
-  CONFIG["DLDFLAGS"] = "-Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress"
+  CONFIG["ARCH_FLAG"] = arch_flag || " #{arch_flag} "
+  CONFIG["DLDFLAGS"] = "-undefineddynamic_lookup -multiply_definedsuppress"
   CONFIG["ALLOCA"] = ""
   CONFIG["codesign"] = "codesign"
   CONFIG["POSTLINK"] = "test -z '$(RUBY_CODESIGN)' || codesign -s '$(RUBY_CODESIGN)' -f $@"
@@ -165,7 +164,7 @@
   CONFIG["EGREP"] = "/usr/bin/grep -E"
   CONFIG["GREP"] = "/usr/bin/grep"
   CONFIG["CPP"] = "$(CC) -E"
-  CONFIG["CXXFLAGS"] = "$(ARCH_FLAG) -g -Os -pipe "
+  CONFIG["CXXFLAGS"] = "#{arch_flag} -g -Os -pipe "
   CONFIG["CXX"] = "xcrun clang++"
   CONFIG["OBJEXT"] = "o"
   CONFIG["CPPFLAGS"] = "-D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags)"
@@ -190,7 +189,7 @@
   CONFIG["build_vendor"] = "apple"
   CONFIG["build_cpu"] = "x86_64"
   CONFIG["build"] = "x86_64-apple-darwin13"
-  CONFIG["RUBY_RELEASE_DATE"] = "2014-02-24"
+  CONFIG["RUBY_RELEASE_DATE"] = "2013-06-27"
   CONFIG["RUBY_PROGRAM_VERSION"] = "2.0.0"
   CONFIG["target_alias"] = ""
   CONFIG["host_alias"] = ""
@@ -210,7 +209,8 @@
   CONFIG["infodir"] = "$(DESTDIR)/usr/share/info"
   CONFIG["docdir"] = "$(datarootdir)/doc/$(PACKAGE)"
   CONFIG["oldincludedir"] = "/usr/include"
-  CONFIG["includedir"] = (ENV['SDKROOT'] || (File.exists?(File.join(CONFIG['prefix'],'include')) ? '' : %x(xcode-select --print-path >/dev/null 2>&1 && xcrun --sdk macosx --show-sdk-path 2>/dev/null).chomp)) + "$(prefix)/include"
+  DEFAULTSDK = ENV['SDKROOT'] || %x{xcode-select --print-path >/dev/null 2>&1 && xcrun --sdk macosx --show-sdk-path 2>/dev/null}.chomp
+  CONFIG["includedir"] = DEFAULTSDK + "$(prefix)/include"
   CONFIG["localstatedir"] = "$(prefix)/var"
   CONFIG["sharedstatedir"] = "$(prefix)/com"
   CONFIG["sysconfdir"] = "$(DESTDIR)/Library/Ruby/Site"
@zenspider

I think @drbrain has some ENV var you can set to avoid my hack.

@drbrain
Sparkle Motion member
drbrain commented May 13, 2014

From stack overflow, try:

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

PS: I wish apple would upgrade their ruby to the patchlevel that has @zenspider's fixes

@zenspider

Huh.. that one on line 71 looks suspect. I don't think that's my change and therefore not my ~ file. :/

@flavorjones
Sparkle Motion member

If someone with the offending version of Xcode/clang could submit a PR with an appropriate extconf.rb change, I'd be happy to ask someone else with a Mac to review. ;)

Otherwise, I'll close this out in 30 days. Thanks!

@zenspider

@drbrain's ENV hack can probably be worked into the extconf w/o much issue.

@mattneub

Very helpful, thanks everyone (although I'm still not clear on the best way to proceed: use the ARCHFLAGS at the command line during gem commands? modify rbconfig.rb? try to build ruby manually?)

@drbrain
Sparkle Motion member
drbrain commented May 14, 2014

IMO:

ARCHFLAGS is the least-effort fix

Building your own ruby is the best fix (rvm, etc can do this for you)

Editing rbconfig.rb is the most "dangerous" fix (not that dangerous at all)

@mattneub

Downsides: (1) The ARCHFLAGS trick is guaranteed to stop working in the future (though one hopes Apple will update its system Ruby by then). (2) I believe that the edited rbconfig.rb will get overwritten next time you install a new version of Xcode...

Once again, fantastic gathering of info; thanks to all.

@zenspider
@flavorjones
Sparkle Motion member

So what actions are necessary, if any, to resolve this in the Nokogiri codebase?

@mattneub
mattneub commented Jun 5, 2014

I'm hoping this will be fixed by Apple in the course of the current Xcode 6 release process.

@drbrain
Sparkle Motion member
drbrain commented Jun 5, 2014

@flavorjones I think setting ARCHFLAGS in the generated makefile upon detection of apple ruby will allow you to work around the apple bug

@flavorjones
Sparkle Motion member
@polozoff

I'm using the ARCHFLAGS command line from above but nokogiri still fails to build. I'm on OSX 10.9.2. Any ideas what data I can collect or other options to try?

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

@zenspider
@flavorjones
Sparkle Motion member
@polozoff

Hi all, Thanks for the quick fix and commit.

I'm going to sound a bit daft here as this is the first time I'm working with git due to a Chef project I've been put on. How do I incorporate this fix into my environment? This is blocking me from getting fog-softlayer installed. I tried cloning nokogiri and getting the fix but building fails as there is no gemspec file and I do not know what I need to do to make progress. Thanks in advance.

@flavorjones
Sparkle Motion member

Building 1.6.3.rc2 now, which will include this fix.

@polozoff

I was able to install. Thanks!

@comutt comutt added a commit to comutt/nokogiri that referenced this issue Jul 21, 2014
@comutt comutt Revert "Fix for stock ruby 2.0.0 on osx 10.9. Fixes #1101."
This reverts commit d9b63d2.
ca1b561
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.