Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 553
Cromulent Avatar asked Jul 22 '09 13:07

Cromulent


People also ask

Does Mac Have gcc by default?

Often times, you need c or gcc compiler to compile open source projects in Mac OS X. The problem is Mac OS X doesn't install the gcc compiler by default.

How do I know if gcc compiler is installed on my Mac?

The name of the C compiler (that was installed along with the command line tools) is gcc. To check that this is now successfully installed, enter "gcc --version" at the prompt.


2 Answers

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

like image 147
Martin v. Löwis Avatar answered Sep 17 '22 21:09

Martin v. Löwis


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 
like image 31
IlDan Avatar answered Sep 17 '22 21:09

IlDan