Installing GCC on OS X Yosemite via Homebrew

Last week I decided to install Mac OS X Yosemite (v10.10), and as expected a lot of things changed under the hood on Mac OS, so things are still not as easy to install as they were on my Mavericks installation.

Almost all of the problems I faced so far I was able to find articles on how to solve them, but when I was trying to install [`fswatch`](https://github.com/alandipert/fswatch “Cross-platform file change monitor” “_blank”) I had a problem with the GCC compiler.

After digging a bit on Homebrew’s GitHub Issues I found that you can edit the GCC formula and apply a patch that will make it work on Yosemite.

#### The Error
When Homebrew was installing the Bootstrap (`make bootstrap`) the following error was presented on my terminal:

“`markup
config.status: executing default commands
make[1]: *** [stage2-bubble] Error 2
make: *** [bootstrap] Error 2

READ THIS: https://github.com/Homebrew/homebrew/wiki/troubleshooting

These open issues may also help:
gcc: compatibility 10.10 (https://github.com/Homebrew/homebrew/pull/31466)
gcc 4.8.3 bottle has invalid omp.h header (https://github.com/Homebrew/homebrew/issues/29670)
MacOS.(gcc|clang|llvm)_version can return nil (https://github.com/Homebrew/homebrew/issues/18781)
“`
#### Solution
It’s easy do resolve the issue, you only need:

“`markup
brew edit gcc
“`

Then you will find the following:

“`ruby
require “formula”

class Gcc < Formula def arch if Hardware::CPU.type == :intel if MacOS.prefer_64_bit? "x86_64" else "i686" end elsif Hardware::CPU.type == :ppc if MacOS.prefer_64_bit? "powerpc64" else "powerpc" end end end def osmajor `uname -r`.chomp end ``` Then add the code below the `osmajor` method definition: ```ruby # edit by b.nelissen 20140805 # tobinjones patch gcc https://github.com/Homebrew/homebrew/issues/29845 patch do url "https://gcc.gnu.org/bugzilla/attachment.cgi?id=33180" sha1 "def0cb036a255175db86f106e2bb9dd66d19b702" end ``` Now you will need to run `brew install gcc` again and you should be good to go.

8 Replies to “Installing GCC on OS X Yosemite via Homebrew”

  1. brew gcc edit -> brew edit gcc

    Reply

    1. Thanks, I’ve already fixed that!

      Reply

  2. I’ve tried this and yet my *brew config* still throws up the error as follows:

    couldn’t understand kern.osversion `14.1.0′

    I’m not sure why the first entry appears twice but output from ‘which -a gcc’ follows:
    $ which -a gcc
    /usr/local/bin/gcc
    /usr/local/bin/gcc
    /usr/bin/gcc

    /usr/local/bin shows the following:

    ls -l /usr/local/bin/gcc*
    lrwxr-xr-x 1 ian admin 55 26 Feb 22:07 /usr/local/bin/gcc -> /Applications//Xcode.app/Contents/Developer/usr/bin/gcc
    lrwxr-xr-x 1 ian admin 46 26 Feb 20:43 /usr/local/bin/gcc-4.2 -> ../Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
    lrwxr-xr-x 1 ian admin 33 24 Feb 22:06 /usr/local/bin/gcc-4.9 -> ../Cellar/gcc/4.9.2_1/bin/gcc-4.9
    lrwxr-xr-x 1 ian admin 36 24 Feb 22:06 /usr/local/bin/gcc-ar-4.9 -> ../Cellar/gcc/4.9.2_1/bin/gcc-ar-4.9
    lrwxr-xr-x 1 ian admin 36 24 Feb 22:06 /usr/local/bin/gcc-nm-4.9 -> ../Cellar/gcc/4.9.2_1/bin/gcc-nm-4.9
    lrwxr-xr-x 1 ian admin 40 24 Feb 22:06 /usr/local/bin/gcc-ranlib-4.9 -> ../Cellar/gcc/4.9.2_1/bin/gcc-ranlib-4.9

    Any idea how to clear the “couldn’t understand kern.osversion `14.1.0′” ?

    Reply

    1. Hi Ian,

      I would go for removing the xCode version of your GCC which might be still installed.

      [Checkout this Issue on HomeBrew](https://github.com/Homebrew/homebrew/issues/36499), and I would also recommend you to create a Issue there if you having an issue hard to solve.

      What were you trying to accomplish when installing the GCC. The error you are seen is not the same as I had, so the solution above (on the post) won’t work.

      Reply

  3. Hi!
    (Warning, I’m a total newb)
    I’m trying to get opencv on my mac (yosemite) and get the exact same error as you when it tries to install gcc.
    I tried to follow your instructions but it doesn’t seem to be working….
    Now, when I type in brew edit gcc, I get:
    blablabla
    if MacOS.prefer_64_bit?
    “powerpc64”
    else
    “powerpc”
    end
    end
    end

    def osmajor
    `uname -r`.chomp
    end

    patch do
    url “https://gcc.gnu.org/bugzilla/attachment.cgi?id=33180”
    sha1 “def0cb036a255175db86f106e2bb9dd66d19b702”
    end

    which is what it should be, right?
    Then, if I type in brew install gcc, I get:
    Error: You must `brew link gmp’ before gcc can be installed

    Did I do something wrong? Could anyone please help me with this?

    Thanks a lot!!
    P

    Reply

    1. Hi Patricia,

      I would say the following, this tutorial is for Beta users of the Yosemite, so if you are having this issue with the `opencv`, you should [open a Ticket on the Official GitHub of the HomeBrew project](https://github.com/Homebrew/homebrew/issues/new), just make sure you read the guidelines on how to do it, otherwise people won’t be able to help you.

      My best bet to solve your problem would be to fully remove the GCC and then install it again.

      My Best Regards,

      Reply

  4. Thank you!

    Reply

  5. Hello, still getting the following error when trying to compile with gcc
    $ make
    cc -o assign1 assign1.c pslibrary.c pslibrary.h
    clang: error: cannot specify -o when generating multiple output files
    make: *** [assign1] Error 1

    Thanks in advance!

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.