5

I installed gcc via homebrew with no errors.

brew install homebrew/versions/gcc49
brew unlink gcc49 && brew link gcc49

But when I try to run gcc, clang is used instead.

~$:gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin15.0.0
Thread model: posix

Edit:

~$:type gcc
gcc is /usr/bin/gcc
~$:type /usr/bin/gcc
/usr/bin/gcc is /usr/bin/gcc
~$:echo $PATH
/usr/local/sbin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin
0
4

Instead of invoking using gcc you need to call gcc-4.9. Alternately you could create an alias for gcc to point to gcc-4.9(although that is risky).

1
  • 2
    Would generally advice against the alias. It can cause no end of trouble if you're trying to use Xcode or something that expects and standard Apple dev environment with clang as the gcc complier and you've got an alias like that.
    – Ian C.
    Dec 9 '15 at 6:55
2

For anyone who stumbles upon this currently (like I did), I found that I needed to locate my version of gcc (which I had installed with brew). This is annoying when gcc --version gives the clang version instead! To find the correct gcc version, run

$ ls /usr/local/opt/gcc/bin | grep gcc
gcc-10
gcc-ar-10
gcc-nm-10
...

So I had gcc-10. Whenever you wish to use gcc just replace it with gcc-10, e.g. man gcc-10. Of course you could write an alias for gcc to gcc-10, but this probably is not a great idea as Xcode seems to rely on the gcc --> clang simlink.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .