Getting gcc on a Mac – oh the pain!

July 16th, 2008 | Categories: Linux, Mac OS X | Tags:

Someone came to visit me today with a MATLAB mex problem and, among other things, I needed to install gcc for them. Now on a Linux machine this would have been trivial. Something like

yum install gcc

or

apt-get install gcc

would do the trick, depending on which flavour of Linux you are using. One command, a quick download and you’re done. Couldn’t be simpler.

I am as green as grass when it comes to Mac usage and so I assumed that there would be some Mac equivalent to these commands but it seems that this is not the case (please please correct me if I am wrong). As far as I can tell, one needs to install something called Xcode in order to get gcc which is 1 Gigabyte in size. You heard me right – 1GB….for gcc! Of course it isn’t just gcc taking up that 1GB – you get lots of other gubbins too – but I don’t want all of the other gubbins. I just want gcc.

But the size isn’t the worst bit. It turns out that you have to go through a registration process in order to get your hands on XCode – giving Apple information such as your email address, home address, what area you work in, what you are going to use XCode for etc etc

All this to get hold of one of the most fundamental open-source applications there is. There has to be a better way. If anyone can enlighten me as to what that better way might be I would be very grateful.

  1. July 17th, 2008 at 11:47
    Reply | Quote | #1

    I’ve been using OS X for a year and a half now and I’ve yet to find an alternative to Xcode in order to get gcc on the system. I think part of the problem is that Apple modify GCC to work with their various frameworks (I forget the term they use for them, but it’s something like that). I found this out while I was playing with their bluetooth API.

    As far as I can tell, Xcode is the only way to get gcc onto a Mac and retain full functionality (i.e. being able to compile code that uses some mysterious Apple framework). That 1GB of space is a fairly hefty price to pay for the privilege of being able to compile, though.

    Perhaps installing Xcode, compiling the vanilla GCC sources using it, then removing Xcode, might work… but that’s a lot of hassle for something so simple, and I’m not even sure it’d work in the end.

    Thanks for the post about my Fourier Transformed Tiger, by the way. Your blog is now in my bookmarks since it seems we’re writing about similar things!

  2. July 18th, 2008 at 16:20
    Reply | Quote | #2

    Annoying isn’t it? And, as I recently discovered, you don’t even get a Fortran compiler, despite the fact that Fortran is a standard part of gcc.

  3. July 20th, 2008 at 18:42
    Reply | Quote | #3

    Hi,

    I use Macitoshes since long time, although I have not a good experience as unix user.
    To use “apt-get”, you may have a look at “Fink” (http://www.finkproject.org/), but I don’t guarantee it does what you want.
    What I am sure, is that you can install gcc and use it on the mac without using Xcode!
    You need to install the “programming packages”, that are not in the default installation of MacOS X, but are in the installation DVD (and you can download from the apple website.. you have to register as a developer, but should be free).
    The issues with Xcode vs the terminal as a compiling environment are mainly about “environment variables” (is this the correct name.. ?) I mean: the default places where the compiler looks for things, but when you fix these, it works.

    About the Fortran compiler, it seems true (it doesn’t come with gcc) but you find good resources here:

    http://hpc.sourceforge.net/

    MacResearch.org

    I am sorry I am not so precise, but I am in a hurry. I can give you details via email.

    Cheers

    Fabio

  4. huy
    August 15th, 2008 at 09:35
    Reply | Quote | #4

    It would be faster if you just install linux on that mac computer :-D.

  5. Sebastian
    February 2nd, 2009 at 20:21
    Reply | Quote | #5

    And it would take less space too …

  6. Anon
    September 14th, 2009 at 14:14
    Reply | Quote | #6

    I just found out that Xcode is supplied with the Mac OS X install disc, that might be helpful because you skip all the signing up, or downloading process. It helped me.

  7. cK
    January 22nd, 2010 at 11:25
    Reply | Quote | #7

    Would you like to install just the gcc instead of all of xcode ? If thats what you were looking for, i think the “packages” folder on you leopard “Installation Disk 2” has gcc4.0 package using which one can just install gcc.

  8. Ingemar
    April 28th, 2010 at 19:35
    Reply | Quote | #8

    cK :Would you like to install just the gcc instead of all of xcode ? If thats what you were looking for, i think the “packages” folder on you leopard “Installation Disk 2″ has gcc4.0 package using which one can just install gcc.

    It does, but when I run that installer separately, I only get some stuff in /usr/lib, but no gcc in /usr/bin! Is there a GCC binary installed, did it just skip some aliases, or is it simply incomplete?

  9. Ingemar
    April 28th, 2010 at 19:50
    Reply | Quote | #9

    @Ingemar
    One more thing…

    At closer inspection, I found that GCC was there, I just had to do

    cd /usr/bin
    sudo ln gcc-4.0 gcc

    and I have GCC. BUT, I don’t get “as”, the assembler. Without that I can’t do much. It seems to be in “DeveloperToolsCLI.pkg”. Is that free software?

  10. MySchizoBuddy
    June 26th, 2010 at 11:30

    Apple is moving away from GCC. This year WWDC Developer videos Apple specially emphasized the move to LLVM for ALL Mac, iPhone and iPad codes.

    if you have macports installed you can just do “sudo port install gcc” thats it.

  11. andreas
    December 3rd, 2010 at 06:17

    >> if you have macports installed you can just do “sudo port install gcc” thats it.

    However, Xcode is a requirement for macports isn’t it? :)