3

Is there a way to change the compiler to gcc from clang? I have the command line tools installed and am trying to use the terminal to compile instead of xcode itself.

user1698555
  • 77
  • 2
  • 6
  • As of Xcode 5 no gcc based compiler is installed as part of Xcode. With Xcode 4 I believe they had gcc alias to llvm-gcc. You have to either use an old version of Xcode or install gcc yourself. – bames53 Sep 24 '13 at 21:28
  • I have Xcode 4, but I don't know how to switch which compiler to use. By default it is using clang. – user1698555 Sep 24 '13 at 22:48
  • What command are you running? – bames53 Sep 24 '13 at 23:17
  • I use make. But when I type that in it says that clang doesn't recognize some of my flags, so it doesn't link correctly. – user1698555 Sep 24 '13 at 23:42

3 Answers3

4

For MacPorts use:

port select --set gcc <group>, <version>

. . as detailed in this answer.

For Homebrew use:

Brew link and brew unlink the package versions that you prefer to use. Note that an "unlinked" package is still installed and usable from /usr/local/opt//, it's just not in the default path.

Community
  • 1
  • 1
Jasper Blues
  • 28,258
  • 22
  • 102
  • 185
  • You do not need to open a new Terminal, you can refresh the profile using `. ~/.profile` – OLL Dec 17 '13 at 14:42
  • Do not do either of these things. If you use mac ports use "port select --set gcc" This is referenced here https://trac.macports.org/wiki/UsingTheRightCompiler . – Jonathan Lisic Jun 02 '14 at 04:01
3

You can install gcc using any ports system (e.g., MacPorts, http://www.macports.org/)

Ilya Verbin
  • 647
  • 5
  • 20
0

If I understand the question correctly you want to compile on terminal using clean gcc compiler instead of gcc provided by system.

I have fixed that issue by setting up symbolic links to the GCC:

ln -s /usr/local/bin/g++-${VERSION} /usr/local/bin/g++
ln -s /usr/local/bin/gcc-${VERSION} /usr/local/bin/gcc

GCC installation shouldn't provide that links (there can be a lot of different versions of GCC, so which should be linked?), but /usr/bin/gcc exists. So if you ask the system for GCC, it will run this one, which is AppleClang14.sth in my case.

Everything should work after adding these links and checking PATH if /usr/local/bin is before /usr/bin/gcc.

It works for me even on GitHub Actions MacOS job.

Norbert
  • 11
  • 3