OSX does not require gcc to run - developer tools are optional. Therefore, you only need to select gcc when compiling. In Xcode, you explicitly chose gcc and make Makefiles, you can set $ (CC) or similarly the full path.
Alternatively rename gcc-4.7 gcc to gcc-4.7 and use this, so gcc is always Apple.
To simplify the use of multiple C ++ compilers, I use macports (either fink or homebrew), which will compile the compilers with the correct fixes, as well as a port selection command to switch between C ++ compilers
source
share