Setting GCC 4.2 as the default compiler on Mac OS X Leopard Setting GCC 4.2 as the default compiler on Mac OS X Leopard xcode xcode

Setting GCC 4.2 as the default compiler on Mac OS X Leopard


Command line usage for all configure scripts:

  cd /usr/bin  rm cc gcc c++ g++  ln -s gcc-4.2 cc  ln -s gcc-4.2 gcc  ln -s c++-4.2 c++  ln -s g++-4.2 g++

Make a record of the current link targets, so you can restore them if you want to.

If you don't want to change the system wide settings, add a directory into PATH before /usr/bin (say, $HOME/bin), and make the symlinks there

I haven't tested whether this affects Xcode projects, since I don't use Xcode (only command line).


In the Project or Target Info Window set the build setting "C/C++ compiler version" (GCC_VERSION).

Or in the Target Info Window you can change the "System C rule" to your favorite GCC version.

Update: Regarding the command line I would leave to Leopard the decision of what should be the default compiler. If you want to use a different compiler with tools like Autotools configure you had better to define the CC variable.

CC=gcc-4.2 ./configure

or

export CC=gcc-4.2


Since neither Apple nor Darwin Ports have the gcc_select program to change the default version of the System compiler (as exists on GNU/Linux), I would like to be on the safe side with XCode (and the rest of the system) and would recommend to leave the symbolic links as they are and instead setup environment variables that overrides which version of GCC to use.

In my .profile file I have the following

export CC=/usr/bin/gcc-4.2export CPP=/usr/bin/cpp-4.2export CXX=/usr/bin/g++-4.2 

And I successfully compiled the following libraries with GCC 4.2 from source.

  • OpenSSL
  • libjpeg
  • libpng
  • zlib
  • gst

However... I could not get Boost 1.39 to acknowledge the environment variables, so to compile Boost with GCC 4.2 I needed to change the symbolic links in /usr/bin/ so they pointed to gcc v4.2

After the long while the Boost libraries were finished compiling with GCC 4.2 I restored the symbolic links back to the original System version gcc-4.0.