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++?
5 Answers
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
.
-
14
-
31For anyone wondering,
brew tap homebrew/versions
is a prerequisite forbrew 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.– AdamOct 31, 2013 at 21:14
-
1It'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. 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 defaultg++
without you having to change any original OSX files.– AdamFeb 24, 2014 at 6:35
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
?
-
@rholt So did you use the same version of gcc as well? I suspect not. 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. Oct 23, 2013 at 7:52 -
3i can't use clang because my code depends on GNU gcc extensions like embedded functions... clang throws tons of errors– MichaelDec 8, 2013 at 21:00
-
1This does not work for me. I installed gcc48 from macports but gcc still points to clang in terminal.– JustinJan 17, 2014 at 3:37
-
@Justin Sounds like you haven't configured
$PATH
, configuration of which is part of the macports installation process. Jan 17, 2014 at 6:27
Accessible and up to date GCC packages are at http://hpc.sourceforge.net/
-
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
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.
-
3Just 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
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/...
-
44You'll find a difference between not supporting GCC and masquerading clang as being gcc. Nov 11, 2013 at 21:10
-
4They're quite different -- lots of existing codebases fail to compile in Clang where they worked fine in gcc/g++.– DestyJan 6, 2015 at 10:56
-
2What'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