How to program in C on Mac without using XCode

Discussion in 'Mac Programming' started by luckydev, Sep 8, 2010.

  1. macrumors newbie

    Sep 8, 2010

    I have just come to Mac world from Linux world and I love my way around in Mac environment. I want to write and practice simple C programs in mac and I was searching for the tools I require. Most (All) of the resources in the web ask me to use XCode as IDE to do programming in C on Mac. XCode, for my purpose seems to be an overkill. I am in no way interested in developing iPhone or Mac GUI application. All I want is

    enter C programs using a text editor,
    compile it ,
    and get the output in a Console.
    How can I do it ?

  2. macrumors 603


    Mar 27, 2009
    The World Inbetween
    The version of GCC for mac comes with XCode. Install xcode, then call gcc form the terminal just like in Linux.
  3. macrumors 6502a

    Apr 1, 2007
    Or grab the GCC binaries from here:

    Then you can compile directly with text editor + terminal.

    I recommend XCode thought just for easier (visual) debug + code sense (intellisense, what ever their calling it this week) which will generally speed coding.
  4. macrumors 6502

    Mar 12, 2010
    Install xcode to get gcc

    vi/emacs are already on your computer

    It's just like any other unix computer with bash/csh
  5. macrumors 68000

    Mar 29, 2009

    Documents robert$ nano hello.c
    Documents robert$ gcc hello.c
    hello.c: In function ‘main’:
    hello.c:4: warning: return type of ‘main’ is not ‘int’
    Documents robert$ ./a.out

    Welcome to Mac OS X
    Documents robert$

    If you type "gcc -o hello hello.c" it will make 'hello' the program, the default is 'a.out'

    Nano is just a simple text editor (free alternative to pico, the pine editor)
  6. macrumors 68040

    Feb 2, 2008
    Seems like you've got a 'void main' going on there. :p
  7. macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
  8. macrumors 68000

    Mar 29, 2009
    Hey, he didn't ask for programming lessons! He's on his own for that.
  9. macrumors G5


    Nov 25, 2005
    Just one thing: If you have any programming questions and ask here for help, please state very very clearly that you are not using XCode. Lots of times people will ask what error message XCode gives, ask you to set a breakpoint somewhere and so on, and if you don't use XCode then this is all a waste of time. In particular I wouldn't want to waste my time giving help on a problem that is caused by some compiler options that would never have happened if you had started out with the XCode templates.

    In other words: Go with the flow.
  10. macrumors 603


    Mar 27, 2009
    The World Inbetween
    I have to disagree, going with the flow means to use Visual Studio for C++ and thats just not on. ;)


    Xcode has a commandline app template, use it.

Share This Page