user1698555
user1698555

Reputation: 77

How to use the gcc compiler in the mac terminal instead of clang

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.

Upvotes: 3

Views: 8348

Answers (3)

Norbert
Norbert

Reputation: 11

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.

Upvotes: 0

Jasper Blues
Jasper Blues

Reputation: 28746

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.

Upvotes: 4

Ilya Verbin
Ilya Verbin

Reputation: 685

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

Upvotes: 3

Related Questions