Skip to content

Instantly share code, notes, and snippets.

@lnrsoft
Forked from alghanmi/gcc-default-fix.sh
Created May 11, 2017 08:37
Show Gist options
  • Save lnrsoft/b77bf4dbbeefaef90b3988e1197b9a91 to your computer and use it in GitHub Desktop.
Save lnrsoft/b77bf4dbbeefaef90b3988e1197b9a91 to your computer and use it in GitHub Desktop.
Change the default g++ compiler on MacOS to be the brew version
#
# Make gcc-4.8 the default compiler
# brew installs gcc-4.8, but does not create symlinks for it to be used
# without the version number.
# This script:
# 1. Generate symlinks for all gcc tools installed by brew
# 2. Make brew-installed software the first in path
#
BREW_CMD="brew"
BREW_BIN="$(brew --prefix)/bin"
LN_APPS="c++-4.8 cpp-4.8 g++-4.8 gcc-4.8 gcc-ar-4.8 gcc-nm-4.8 gcc-ranlib-4.8 gcov-4.8"
OLD_PWD=$(PWD)
#Make sure brew is installed
type -P $BREW_CMD &>/dev/null || { echo "$BREW_CMD is not installed."; exit 1; }
#Generate Symlinks
cd $BREW_BIN
for app in $LN_APPS
do
LN_NAME=$(echo $app | sed 's/\(.*\)-4.8/\1/')
ln -s $app $LN_NAME
done
#Prepend brew's path to $PATH
echo '#Making brew apps the first in your path' >> ~/.bash_profile
echo 'PATH=$(brew --prefix)/bin:$PATH' >> ~/.bash_profile
cd $OLD_PWD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment