Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

After installing Xcode 4.3.1 on OS X Lion, I have lost my GCC compiler. I need this for my study. Does anyone know how I will install this? All I have been able to find was people suggesting to install Xcode 4.3.1 but with the latest Xcode build, Apple has moved the GCC compiler inside the Xcode.app and it doesn't seem to be the same version of the GCC compiler as the one bundled with previous versions of Xcode.

share|improve this question

3 Answers 3

up vote 24 down vote accepted

Open XCode go to preferences under downloads install command line tools

share|improve this answer
2  
This was definitely the easiest way to do it. Thanks. –  SimonBS Apr 20 '12 at 7:13

There have been a couple of blog posts about how to do this recently, in the context of trying to compile Ruby 1.8.7 (mine and others). The short answer:

Install Command Line Tools (in Xcode: Preferences > Downloads > Components; or you can go to Apple and download them separately if you don't have/want Xcode installed) - this installs a gcc command, but it's actually clang Install Homebrew (instructions), a package manager for OS X

Then, install the 'dupes' homebrew repository and from it the genuine GCC 4.2 compiler:

brew update
brew tap homebrew/homebrew-dupes
brew install apple-gcc42

/usr/bin/gcc will still be i686-apple-darwin11-llvm-gcc-4.2, but /usr/local/bin/gcc-4.2 will be i686-apple-darwin11-gcc-4.2.1 (and associated tools, g++-4.2 and so forth, also in /usr/local/bin)

Then, you can use whatever mechanism your build process uses (for instance, setting the CC and CXX environment variables appropriately) to select those compilers rather than the clang versions.

share|improve this answer
    
I really wish I had found your solution a few days ago. I fought it for two days straight. I'd +20 if I could. –  Chance Mar 24 '12 at 15:13

I don't use Xcode 4.3 for actual Xcode Projects, only for command line source compilation, and had the same issue. You can bring back your gcc and cc commands with the below commands from terminal:

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++

This will make system wide changes, so be sure that's what you want before doing it.

For these commands to work you'll also need the Command Line Tools for Xcode to be installed, if you don't already have them installed. The Tools can be installed through Xcode's downloads preference pane.

share|improve this answer
2  
One suggestion: instead of removing the old binaries (line 2 of the script), perhaps just put them in an archive directory under /usr/bin). That way if you need them you can still invoke them by absolute path. –  Scott Wilson Mar 13 '12 at 13:10
    
Good suggestion. Do with them as you will, even: mv cc cc.orig && mv gcc gcc.orig or some such thing. –  Lantrix Mar 14 '12 at 2:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.