Hello everyone!
I believe many Mac users have encountered this problem so I decided to post a blog to gain free contributions help them install GNU's GCC. GCC has many useful libraries that Clang (Mac's default c++ compiler) doesn't have. Such as the classic <bits/stdc++.h>
and also the Policy Based data structures.
SO let's get to the tutorial. Have Terminal.app
opened up because we will be typing a lot of commands. Type cd ~
in the Terminal and press enter, this makes the computer go to the root folder. I will assume that your Terminal is always in the root folder for this tutorial.
Btw, any time you think your Terminal is getting a bit too messy, type clear
to clean things up.
Setting up Homebrew
Installing GCC
Now that Homebrew is ready, it's time to download what you came here for. This process is actually much simpler than installing Homebrew. All you have to do is type: ~~~~~ brew install gcc --force-bottle ~~~~~ If it doesn't work, try: ~~~~~ homebrew install gcc --force-bottle ~~~~~ --force-bottle
just makes sure homebrew downloads the precompiled version of gcc (which is a lot faster than the original version).
Now GCC is installed!
Using GCC
To compile with the newly installed GCC, we need to know the version of this gcc. Open up finder and go to the homebrew folder, then go to Cellar -> gcc -> (whatever version number is here) -> bin. Here in the bin
folder, you can see the gcc and g++ versions. Here is mine for example: