codegourmet

savory code and other culinary highlights

Compiling Ruby 1.8.7 on OSX 10.9 Mavericks

| Comments

Problem

When compiling ruby on a colleague’s OSX machine for a legacy project, we ran into the following error: C compiler cannot create executables

1
2
3
4
5
$ rbenv install ruby 1.8.7-p352
<--- snip --->
Downloading ruby-1.8.7-p352.tar.gz...
<--- snip --->
configure: error: C compiler cannot create executables

Background

The reason for this is that Apple doesn’t bundle gcc for newer versions of Xcode, but instead bundles llvm-gcc. llvm-gcc is mostly compatible with gcc, but not completely [unverified source: doesn’t compile gcc itself].

Solution

You can easily install gcc-4.2 via homebrew dupes:

1
2
brew tap homebrew/dupes
brew install apple-gcc42

(source: https://coderwall.com/p/lqpp8w)

And then run

1
rbenv install 1.8.7-p375

Additional resources

  • the rbenv issue itself is documented on github
  • the gcc vs. xcode situation is discussed on Hacker News
  • we also found instructions for building gcc from source on Caius Theory

Happy Coding! – codegourmet

Comments