How to install the gcc compiler on a mac

Hi, I was just wondering, I have been learning c++ on a mac and I have no way to compile my code. I need to know how to install gcc on my MacBook.

thanks!

1 Like

gcc on my mac was installed when I installed xCode from the AppStore:

SF:git sflanders95$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
SF:git sflanders95$ which gcc
/usr/bin/gcc

XCode in the AppStore Link (via itunes)  or 

macappstores://itunes.apple.com/us/app/xcode/id497799835?mt=12&extRefUrl2=&ign-refClientId=3z3N3sSpz6fYz4qozAVmz1HWvRnPdK&mt=12

1 Like

That’s actually Clang, not GCC. You could try using Homebrew.

2 Likes

if it “has” to be on the mac then xcode is probably the easiest - although I code using atom or visual studio code :slight_smile: not the xcode ide

xcode-select --install

in a mac terminal should get you where you need to be.

after install 

$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

This https://hub.docker.com/_/gcc/ is way more fun!

1 Like

Hello there, I am also using VScode for my cpp programming and facing some issues while using some new features from C++ 17. Do you have any suggestions to solve this issue ?
I am using microsoft’s C/C++ compiler extension.