From: Mac install GCC
The development toolchain in your Mac is all about Xcode, but it's not necessary to install a Xcode if you just want to use gcc,g++ to compile C + + code. Update: Version 4.3 of Xcode has released the graphical development interface and command-line tools separately. And even if Xcode is installed, the default GCC compiler is LVMM, not the pure GNU gcc. If you want to use pure gcc, the best way is to manually compile one yourself. There are two main methods:
1. Installation via homebrew
This method is relatively simple, if the MAC is already installed homebrew, the specific command:
Brew Tap Homebrew/versions
Brew install [flags] gcc49
where [flags] some need to support the language of eucalyptus, such as –enable-cxx–enable-fortran
2. Github
Reference Https://github.com/kennethreitz/osx-gcc-installer
3. Install by hand
This method can install the latest version of GCC, or any other required version
version=4.8.0
prefix=/usr/gcc-$ (VERSION)
Languages=c,c++,fortran
Make= ' make-j2′# compiled with two cores
Brew-path () {Brew Info $ | head-n3 | tail-n1 | cut-d "-F1;}
# Prerequisites
Brew Install GMP
Brew Install MPFR
Brew Install LIBMPC
# Download & Install the latest GCC
Mkdir-p $PREFIX
mkdir TEMP-GCC
CD TEMP-GCC
wget ftp://ftp.gnu.org/gnu/gcc/gcc-$VERSION/gcc-$VERSION. tar.gz
Tar xfz gcc-$VERSION. tar.gz
RM gcc-$VERSION. tar.gz
CD gcc-$VERSION
mkdir Build
CD Build
.. /configure \
–prefix= $PREFIX \
–with-gmp=$ (brew-path GMP) \
–with-mpfr=$ (Brew-path mpfr) \
–with-mpc=$ (Brew-path libmpc) \
–program-suffix=-$VERSION \
–enable-languages= $LANGUAGES \
–with-system-zlib \
–enable-stage1-checking \
–enable-plugin \
–enable-lto \
–disable-multilib
$MAKE Bootstrap
Make install
# Uncomment for cleanup ...
# CD: /.. /..
# Rm-r TEMP-GCC
When you are finished, you will install GCC in/usr/gcc-4.8.0, and then you can create a soft link to the GCC or add the bin path to the $PAHT variable
MAC development Environment Configuration Related: Installing GCC