Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set cc to gcc instead of clang on OSX Yosemite

I've been trying to get Mac OSX Yosemite to use gcc instead of clang when cc is invoked, but no matter what I do, it refuses to play along. I've already tried changing my bash_profile/bashrc and even relinking the symlink, but to no avail--every time I invoke "cc" it is still clang that runs. I'm trying to force it to be gcc instead (and no, just calling gcc is not an option).

I previously asked a similar question (Make gcc default c compiler on Yosemite/disable clang).

like image 286
Hendrik Avatar asked Jan 06 '15 20:01

Hendrik


2 Answers

Neither OS X nor Xcode comes with real GCC. For compatibility with scripts which assume the compiler is called "gcc", it has executables by that name, but they are all fronts for Clang. No amount of symlinking, setting environment variables, or setting up aliases will allow those executables to run real GCC.

If you want GCC, you need to install it. You can do that using one of the package managers, such as MacPorts (the one I'm familiar with). I'm sure you could also use Homebrew.

You should not modify anything in /usr/bin. If you've already done so, you should restore what you've changed, if possible.

Well-behaved package managers will also not modify that directory. They should install to a separate directory such as /opt/local/bin, /usr/local/bin, or the like. In that case, you will want to modify your PATH to put those directories earlier than /usr/bin.

like image 118
Ken Thomases Avatar answered Oct 18 '22 22:10

Ken Thomases


You shouldn't do this. A lot of tools rely on the installation binaries to point to what they should. Another option is to set the environment variable CC to gcc, and invoke compilation with $CC ... rather than cc ... ; this environment variable will also be picked up when building packages via configure (autotools) or cmake.

This is also a compatible approach with MacPorts versions of gcc (like the much more up to date gcc-4.9.2), which can be set up with: sudo port select --set gcc mp-gcc49

like image 5
Brett Hale Avatar answered Oct 18 '22 20:10

Brett Hale