Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update g++ compiler on OSX

Tags:

c++

macos

g++

I tried using this tutorial to download the newest version of g++, and I changed the version number from 4.7 to the newest (which is believe is) 8.1. But I get the following errors

Error: No available formula with the name "gcc81"
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
git -C "$(brew --repo homebrew/core)" fetch --unshallow

Error: No previously deleted formula found.
==> Searching for similarly named formulae...
==> Searching local taps...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.

Does anyone know how to update my g++ version? This is what I get when I try to find out my current version.

g++ --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Sorry Im such a noob, I really trying to learn here.

like image 688
Brittany Garcia Avatar asked May 24 '18 05:05

Brittany Garcia


1 Answers

I know this post is a little old but I can shine some light regarding how to accomplish this.

Firstly, to install gcc/g++ using Homebrew, you should use the following command as mentioned in the comments above: brew install gcc

After doing this, Homebrew should place the installed binaries/symlinks in the correct folders.

To correctly setup the gcc/g++ command on mac to use the version you just downloaded, I do this by not changing the symlinks gcc/g++ but instead creating aliases for both gcc and g++ within my shell environment.

alias gcc='gcc-10'
alias g++='g++-10'

gcc-10 and g++-10 were downloaded using Homebrew. When doing this, Homebrew places gcc-10 and g++-10 in /usr/local/bin (which is on the path) and it allows you to create an alias for the regular gcc/g++ commands which point to the versions installed by Homebrew.

After doing this, running the command g++ --version should give you the following:

g++-10 (Homebrew GCC 10.2.0) 10.2.0
Copyright (C) 2020 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.

You may need to restart your terminal or run source ~/.bashrc depending on the type of shell you're using.

like image 79
achristoforides Avatar answered Sep 27 '22 21:09

achristoforides