Can't install mysql gem on OS X

2019-01-13 02:51发布

问题:

I'm doing a

sudo gem install mysql

on OS X to install the mysql gem. This fails with the following output:

Building native extensions. This could take a while...

ERROR: Error installing mysql:

ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb

checking for mysql_ssl_set()... yes

checking for rb_str_set_len()... yes

checking for rb_thread_start_timer()... no

checking for mysql.h... yes

creating Makefile

make "DESTDIR=" clean

make "DESTDIR="

compiling mysql.c

linking shared-object mysql/mysql_api.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: * [mysql_api.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/mysql-2.9.1 for inspection.

Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-13/2.0.0/mysql-2.9.1/gem_make.out

Any idea what could be causing this? I have mysql installed with homebrew if that makes a difference.

回答1:

From Apple's Xcode/Clang release notes:

The Apple LLVM compiler in Xcode 5.1 treats unrecognized command-line options as errors. This issue has been seen when building both Python native extensions and Ruby Gems, where some invalid compiler options are currently specified. Projects using invalid compiler options will need to be changed to remove those options. To help ?ease that transition, the compiler will temporarily accept an option to downgrade the error to a warning:

-Wno-error=unused-command-line-argument-hard-error-in-future

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



回答2:

Seems to be an issue with Apple's rbconfig.rb:

$ grep -n DLDFLAGS /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin13/rbconfig.rb
82:  CONFIG["LIBRUBY_DLDFLAGS"] = "-undefineddynamic_lookup -multiply_definedsuppress -install_name $(libdir)/$(LIBRUBY_SO) -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(ruby_version)  $(XLDFLAGS)"
84:  CONFIG["EXTDLDFLAGS"] = ""
125:  CONFIG["DLDFLAGS"] = "-undefineddynamic_lookup -multiply_definedsuppress"

Removing the -multiply_definedsuppress should allow it to install.



回答3:

This is due to Xcode 5.1 - its already reported as a bug to Ruby.

https://bugs.ruby-lang.org/issues/9624

There is some more additional discussion here: Ruby Gem install Json fails on Mavericks and Xcode 5.1 - unknown argument: '-multiply_definedsuppress'



回答4:

The above answers are correct. The easiest fix though is to rebuild ruby on your machine. Gem extensions use the ruby build configuration when it was itself built and if you built your ruby before the Xcode 5.1, its build configuration contains the offending flags.

This should fix it for all of the many affected gems.