Skip to content

Instantly share code, notes, and snippets.

@alghanmi
Last active May 11, 2017 08:37
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save alghanmi/8853646 to your computer and use it in GitHub Desktop.
Save alghanmi/8853646 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
@alghanmi
Copy link
Author

alghanmi commented Feb 6, 2014

curl -s -o gcc-default-fix.sh https://gist.github.com/alghanmi/8853646/raw/gcc-default-fix.sh
chmod 755 gcc-default-fix.sh
./gcc-default-fix.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment