views:

9811

answers:

3

I'm sure there must be a way to do this. As you are probably aware the latest versions of Xcode (and in fact I think all versions of Xcode) on Leopard come with GCC 4.0.1 and GCC 4.2. GCC 4.0.1 is the default system compiler while GCC 4.2 is an optional compiler you can set in the Xcode project settings.

Does anyone know how to set GCC 4.2 as the default compiler for all options? Preferably command line use as well as configure scripts still use GCC 4.0.1 rather than GCC 4.2 no matter what I do in Xcode. I'm assuming it is simply a case of changing a path variable or some such but I am stumped on this one.

Any help is appreciated. Thanks.

+7  A: 

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
IlDan
Unfortunately I already know about those, but they are per project. I am talking about when you invoke GCC from the commmand line. No matter what I set the rules for in Xcode it will always use GCC 4.0.1 from the command line.
Simon
my fault sorry. I'm updating it
IlDan
I find 'export CC=gcc-X.Y' more practical (and *nix-like) when compared with the rm/ln -s solution.Easy to revert if something goes wrong, easy to setup user/system-wide, it only requires one to edit .bash_profile (or your favorite shell rc).
lsdr
+2  A: 

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).

Martin v. Löwis
This used to be handled by the `gcc_select` script, but it seems that Leopard / Xcode 3.1 doesn't provide it anymore? I haven't used OS X in years, so I'm a bit out of touch...
ephemient
Thank you, that fixed the issue. Just as an aside if anyone else is planning on doing this, I highly recommend putting the new symlinks in a different directory so that if you ever want to revert back to your original settings you just have to delete the symlinks or move them to a different directory.
Simon
Martin, a related question, how can you tell setup.py / pydistutils.cfgwhich CC and which -arch to use ?For example, I want gcc-4.2 -arch ppc only (because my gcc-4.2 has no/usr/bin/i686-apple-darwin8-g++-4.2.1). Thanks
Denis
@Denis: They use the CC in the installed Makefile (distutils.sysconfig.get_makefile_filename()). In principle, setting CC and CXX environment variables should override that.
Martin v. Löwis
+5  A: 

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.2 export CPP=/usr/bin/cpp-4.2 export 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.