59

I just noticed that after installing OS X 10.9, the g++ compiler links to the clang compiler. Is there anyway to revert back to gcc/g++?

1
  • it's strange that i find that on os x 10.10 gcc is actually not links to clang, but something like that. Do you know the exact difference between the two? Nov 6, 2014 at 12:42

5 Answers 5

72

It has been this way for a long time already. The "GCC" that came with 10.8 was really GCC front-end with LLVM back-end.

The best way to get GCC is via Homebrew. After the one-line homebrew install command on the bottom of the linked page, you just need:

$ brew install gcc49

Unlike macports, Homebrew doesn't clutter your system dirs and it's much better at managing versions and uninstalls. It also doesn't require the crutch known as sudo.

8
  • 14
    Your statements about macports are misleading and off topic.
    – trojanfoe
    Oct 23, 2013 at 7:59
  • 31
    For anyone wondering, brew tap homebrew/versions is a prerequisite for brew install gcc49 Oct 31, 2013 at 19:39
  • 18
    @trojanfoe blunt and a little mean, sure. But how is it misleading? It's certainly on-topic; OP is clearly looking for the best way to get GCC and implying that all package managers are exactly the same would be misleading.
    – Adam
    Oct 31, 2013 at 21:14
  • 1
    It's misleading as it isn't true; homebrew causes way more system clutter and has many fewer ports available. I suggested macports and you suggested homebrew, which is fine, and that's how it should stand. The point is subjective and the argument we are about to have about it makes it off-topic.
    – trojanfoe
    Oct 31, 2013 at 21:18
  • 3
    @Eddy the default name of Homebrew's GCC is g++-49. You can change that by adding a Bash alias or a symlink in /usr/local/bin. That directory should already appear first in your $PATH so a symlink should override the default g++ without you having to change any original OSX files.
    – Adam
    Feb 24, 2014 at 6:35
11

You'd have to install it from macports:

$ sudo port install gcc49

However I am not certain how you'd integrate gcc into Xcode 5, however you don't mention why you cannot use clang?

10
  • @rholt So did you use the same version of gcc as well? I suspect not.
    – trojanfoe
    Oct 23, 2013 at 7:46
  • @rholt I don't think so; your motivation is that your work compiles during the examination and for that you'd need to use the exact version of everything on both systems (and both systems would need to be the same platform). So you may as well use clang if you cannot reproduce it entirely.
    – trojanfoe
    Oct 23, 2013 at 7:52
  • 3
    i can't use clang because my code depends on GNU gcc extensions like embedded functions... clang throws tons of errors
    – Michael
    Dec 8, 2013 at 21:00
  • 1
    This does not work for me. I installed gcc48 from macports but gcc still points to clang in terminal.
    – Justin
    Jan 17, 2014 at 3:37
  • @Justin Sounds like you haven't configured $PATH, configuration of which is part of the macports installation process.
    – trojanfoe
    Jan 17, 2014 at 6:27
4

Accessible and up to date GCC packages are at http://hpc.sourceforge.net/

1
  • I just realized your answer was the same as the one I was going to post. Anyway let me add some more directions. Download their package and follow their directions. After installing to /usr/local/bin, you might want to edit your PATH variable and append /usr/local/bin to the front of PATH. This will guarantee that when you call gcc or g++ you are actually calling the correct one and not an older mac deprecated compiler. Note: this step is only important if you have a g++ compiler in the /usr/bin directory. I do since this computer had 10.5 originally. Sep 23, 2014 at 4:07
3

you can also get a g++ compiler from http://hpc.sourceforge.net/. They have the compiler in a pre-built package. Just download and follow their directions. Note you may need to change your executable PATH and have /usr/local/bin ahead of /usr/bin. This is to insure g++ calls the right compiler.

1
  • 3
    Just out of curiosity why was this down voted? The post explains how to get an alternative version of the g++ compiler and change your system settings so that g++ no longer calls clang's C++ compiler. Isn't that what the original poster was asking? Jul 27, 2015 at 0:38
-1

This is by design, and not new in OS X 10.9. Apple deprecated GCC a long time ago. Just use Clang, or if you need fortran/openmp/..., install GCC yourself through homebrew/macports/...

4
  • 44
    You'll find a difference between not supporting GCC and masquerading clang as being gcc.
    – deadalnix
    Nov 11, 2013 at 21:10
  • 4
    They're quite different -- lots of existing codebases fail to compile in Clang where they worked fine in gcc/g++.
    – Desty
    Jan 6, 2015 at 10:56
  • 2
    What's the point? It doesn't stop me from using Gcc, doesn't stop me from reverting the only observable difference alias g++ /path/to/g++, and since this hardlink doesn't display a message "USE CLANG INSTEAD OF GCC, CAUSE WE HATE FREE SOFTWARE", it doesn't even communicate their intent. It looks like a solution looking for a problem. Sep 10, 2018 at 14:33
  • 3
    Apple isn't entitled to deprecate GCC.
    – Arne
    May 2, 2019 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.