First thing to do is install gcc4.7, I will be using MacPorts.
If you want to see what versions of gcc you have at your disposal you can run:
$sudo port search gccIf you are interested in gaining C++0x/ C++11 functionality you might want to consult http://gcc.gnu.org/projects/cxx0x.html to select a version that suites your needs.
Now to install the new/other version:
$sudo port install gcc47If I were to see what version of gcc I was running by executing:
$gcc -vI would see that it still points to a 4.2 version of gcc. What you need to do is "select" the version of gcc you wish to use. You may need to install gcc_select first, but it might already be installed:
To actually select the working version of gcc, first see what you have to choose from:
$sudo port install gcc_select
$port select --list gccThen make the choice:
$sudo port select --set gcc mp-gcc47At this point running gcc (even to display the version number) may result in an error message as such:
gcc-mp-4.7: error trying to exec '/opt/local/bin/i686-apple-darwin10-llvm-gcc-4.2': execvp: No such file or directoryIn which case you have to rehash your links. To see if gcc is indeed hashed run:
You will probably see gcc listed in there, rehash gcc's link:
$hash gccChecking the version number of gcc you should see the version you selected as working! In my case gcc4.7 is now working!