Home > other >  Can't change my compiler from clang to gcc on mac
Can't change my compiler from clang to gcc on mac

Time:01-04

I'm following a tutorial on youtube to try and change my compilers from clang to gcc. It states that after installing gcc with homebrew, I can cd /opt/homebrew/bin and then run the commands:

ln -s gcc-11 gcc
ln -s g  -11 g  

After following all the steps, this is the furthest I have come. In the terminal, typing gcc --version shows me that I am indeed using:

MacBook-Air ~ % gcc --version
gcc (Homebrew GCC 12.2.0) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

However, running g --version still shows clang:

MacBook-Air ~ % g   --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

What am I doing wrong? I've followed multiple other forums and youtube videos and none of the commands are working on my device. FYI I'm working on a newly started Macbook air that literally has chrome and vscode and thats it.

CodePudding user response:

In order to use this approach, you need to ensure that /opt/homebrew/bin appears in your $PATH before /usr/bin. You can check this with:

$ echo $PATH

Assuming you've ensured that, you can check for shell aliases with:

$ type g  

Another alternative that doesn't require messing with $PATH is to define shell aliases, eg:

$ alias gcc='gcc-11'
$ alias cc='gcc-11'
$ alias g  ='g  -11'
$ alias c  ='c  -11'
  • Related