GCC 4.6 on OSX

OSX 2011. 6. 20. 16:20

Building GCC [4.6] on MacOSX

The objective here is describe a didactic way to build GNU GCC on MacOSX. In order to compile GCC you need three libraries: GMP, MPFR and MPC. To organize I usually create folders for each purpose. In this case, three, respectively: source, build and install. [It's not a rule]. My original enviroment is MacOSX 10.6.4 and gcc version 4.2.1 (Apple Inc. build 5659). All files will be on GCC folder, the description below shows:


$ mkdir ~/Downloads/GCC/ # gmp, mpfr and mpc
$ mkdir ~/gcc46_64 # store libs objects and include

Step #1 – Download

$ wget ftp://ftp.gmplib.org/pub/gmp-5.0.1/gmp-5.0.1.tar.bz2
$ wget  http://www.mpfr.org/mpfr-3.0.0/mpfr-3.0.0.tar.bz2
$ wget http://www.multiprecision.org/mpc/download/mpc-0.8.2.tar.gz

Step #2 – Unpack


Step #3 – Build: GMP

$ mkdir gmp-build
$ cd gmp-build
$ ../gmp-5.0.1/configure --prefix=$HOME/gcc46_64
$ make install

Note 1: I’m using with ABI=64
Note 2 : Maybe you’ll get some unresolved symbols to GMP and MPFR on linking time, never mind.

Step #4 – Build: MPFR

$ cd ..
$ mkdir mpfr-build  
$ cd mpfr-build
$ ../mpfr-3.0.0/configure --prefix=$HOME/gcc46_64 --with-gmp=$HOME/gcc46_64
$ make install

Step #5 – Build: MPC

$ cd ..

$ mkdir mpc-build
$ cd mpc-build
$ ../mpc-0.8.2/configure --prefix=$HOME/gcc46_64 --with-gmp=$HOME/gcc46_64 --with-mpfr=$HOME/gcc46_64
$ make install

Problems? If something goes wrong…

../../mpc-0.8.2/src/mpc.h:25:17: error: gmp.h: No such file or directory
../../mpc-0.8.2/src/mpc.h:26:18: error: mpfr.h: No such file or directory

I fixed by adding symbolic links:

$ cd ~/Projects/GCC/libs/mpc-0.8.2/src/
$ ln -s ../../install/include/mpf2mpfr.h .
$ ln -s ../../install/include/mpfr.h .
$ ln -s ../../install/include/gmp.h .

Step #6 – Download & Build GCC (~4.6)

I used GCC from git (fda0037801fb258a2191aba59e1e9f0df019e3b6) and I don’t know if it will work on newer versions. You’ll have to try. Sorry. [Howto: GitMirror]. Use git checkout to specify one commit.

$ cd ~/Downloads/GCC/gcc-4.6.0
$ mkdir build
$ cd build
$ ../configure --prefix=$HOME/gcc46_64 --with-gmp=$HOME/gcc46_64 --with-mpfr=$HOME/gcc46_64 --with-mpc=$HOME/gcc46_64 --disable-checking --enable-languages=c --program-prefix=my- --enable-languages=c,c++,fortran

$ make
$ make install




: