MacBook – Can Xcode compile C programs

gccmacbook pro

For the last couple of hours, I have been trying to find and install a gcc compiler so that I can compile C programs using eclipse C/C++ IDE. Eclipse doesn't come with a compiler, so I tried to find one but I haven't found a way to get one. I looked up Xcode in the App Store and I heard from some sites that it can compile C programs. Can it compile C programs? Is it better than Eclipse? If not, does anyone know where I can find a gcc compiler for my Mac? I'm running Mac OS X Lion.

This is the version of Eclipse I am running: http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers-includes-incubating-components/indigosr2

Best Answer

To get a free C/C++ compiler you have to download Xcode. It includes two C compilers; clang (the compiler Apple currently supports) and an old version of gcc. (Note current versions of Xcode >=5 I think only have clang) Make sure you install the command line tools if you want to use the compilers from outside Xcode. (These command line tools also seem to be available from Apple's developer site if you register but I would get them via Xcode unless you have a very good reason and understand the difference).

All other compilers I know of use one of these two compilers and their binary tools to set themselves up. (e.g. package management systems like macports, fink and homebrew need these command line tools to run parts of their infrastructure as well as to compiler their ports - however these package managers include ports of other c compilers e.g. newer versions of gcc.)

IDEs like Eclipse use these command line compilers to do the building of programs.

There are some commercial compilers like Intel's C++ compiler but I do not know if these require Xcode or are C compilers.