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

  • Do you need to compile C programs or need to use gcc (and which version) The default C compiler in Xcode is clang. Or do you need an ide both Xcode and Eclipse call the same command line compilers. – user151019 Jun 25 '12 at 9:11
  • @Mark I just want to be able to compile and run C programs on my mac, if i can do that with eclipse then awesome but if its gonna be a hassle i can just download Xcode. See my edit if you are interested in the version of eclipse i am running. – John Jun 25 '12 at 9:15
  • I would try Xcocde first to compiler C programs unless you must use eclipse it should provide all the functions of an IDE you need and is all set up. I however use eclipse for C++ as Xcode had some issues with C++ namespaces for me (albeit not tried the latest version) – user151019 Jun 25 '12 at 9:33
  • 1
    XCode installation has been recently enhanced to make installing various components like command line tools a breeze. Download XCode directly from the AppStore. The first time you run it, it prompts for additional component installs. – ephsmith Jun 25 '12 at 12:37

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.

  • When i download Xcode will my eclipse automatically be able to find the compiler and the includes and stuff like that? – John Jun 25 '12 at 9:23
  • @John I think so or it did for me with pre clang compilers - for C this will not matter - and it is easy enough to chnage – user151019 Jun 25 '12 at 9:30

Yes, Xcode can compile C/C++ programs.

Another option would be to use Macports to install gcc.

Edit: As stated in the comments, you actually need Xcode to install Macports, I blame me missing this on the fact that I haven't had an OS X install without Xcode since I started using OS X. Still, Macports is good for getting slightly more up-to-date versions of things, Xcode tends to be more about stable than new (not that it matters all too much for most users when it comes to C compilers).

  • Xcoce does include a gcc compiler - just an old version - and for c that is probably sufficient – user151019 Jun 25 '12 at 9:11
  • Is Xcode better than eclipse? if not, can you point me in the right direction for Macports? – John Jun 25 '12 at 9:12
  • 1
    @John macports is at the URL mludd gives but needs Xcode first – user151019 Jun 25 '12 at 9:29
  • MacPorts requires XCode be installed first, as it actually builds itself using the compiler from XCode. (You have to install the command line tools in XCode too.) – Fake Name Jun 25 '12 at 10:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .