Can't install gems after upgrading to Xcode 5.1? Here's the fix
Today while setting up new a development envoirnment on a machine running OS X Mavericks with Xcode 5.1 (The updated Xcode allowing for iOS 7.1 development), I ran into a number of gem compilation issues. After some research it appears that an update made to clang breaks a large number of gems (yajl-ruby, puma, rmagik, json, memcached, and many more)
###The Problem
Here’s what I’ve been seeing over and over with a number of gems:
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
Clang is the C family (C/C++/Objective-C) front-end for the llvm compiler, and is the default C family compiler on OS X. It’s gcc compatible and powers the gcc binary installed by Xcode and relied upon by many gems:
jlorich$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
It seems that with clang 5.1 any unknown/unused command line arguments will cause builds to fail, breaking a large number of gems. I’ve submitted an issue with yajl-ruby, which was the first place I noticed the problem, but this is the cause of failing installations with many other gems.
The solution (for now)
After a bit of searching I have found a successful workaround for what should be any gem having this issue. To force the compiler to ignore the problem simply add this before your install command:
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future
For example, to successfully install librarian-chef on OS X after installing Xcode 5.1, run:
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install librarian-chef
Or to bundle:
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future bundle install
This is not a permanent fix, as Apple has explicitly stated that this will be a hard error in the future, but it will get things working for now. Hopefully each gem with failing builds will make the necessary changes soon.
For a bit more information check out the latest Xcode release notes (See the section titled Compiler).