Hi Codeforces,
Today I am gonna tell you the complete solution on how to use gcc compiler instead of using apple CLANG for those who are using MAC.
Go to brew official website and copy the code below "Install Homebrew", it will be like
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Open Terminal from the launchpad and paste it in your terminal and press enter to run it.
Now it will ask for the sudo password and then enter your mac password and then run it. Next it will ask press RETURN to continue and hit return. After then it will take take some time to download and install it on your mac.
After some time, it will show: View this image. Then copy the first code and then run it and then copy the second code and then run it. If it doesn't run reopen the terminal and then run it. It will show something like this.
Now reopen the terminal and type
brew
and press enter. It should show the list of all the brew commandsCongratulations now you have successfully installed brew on your mac.
Now its time to install GCC compiler in your MAC.
Open terminal and type
brew install gcc
Now type
g++-12 --version
and it will show the current version of the gcc compiler installed.Now type
g++ --version
it will show apple clang instead of gcc. Something like this.That means the current default compiler is clang not gcc. So we have to set it to GCC compiler as the default compiler.
Now type
cd /opt/homebrew/bin
, press enter and then typeln -s g++-12 g++
and press enter.Now again type
g++ --version
and it will show something like this. That means you have successfully installed gcc in your MAC and has been set as the default compiler.
Now whenever you compile a code in VS CODE, sublime etc. it will compile default with the GCC compiler instead Apple Clang.
I will be pleased if this blog is helpful to anyone. Please share this blog so if anybody is trying to install gcc can see this solution. Thank you. Have a nice day:)
Still it showing me the clang one only on running g++ --version, How to solve this issue. If you have any idea please answer
Still suffering? Have you tried to run
/opt/homebrew/bin/g++-14
afterbrew install gcc
?I tried this but then it showed FATAL ERROR
Show it
This doesn't work anymore.
However, the current version as of today is g++ 14.