c programming on terminal

Discussion in 'Mac Programming' started by manee, Oct 18, 2011.

  1. macrumors newbie

    Joined:
    Sep 5, 2011
    #1
    can someone please tell me how to write and compile a c program in terminal. i use xcode and don't really like it. :confused:
     
  2. macrumors 601

    talmy

    Joined:
    Oct 26, 2009
    Location:
    Oregon
    #2
    Edit the file with any text editor (I'm an emacs fan myself, but most people like vi and there is also nano and probably others). Compile with the gcc command.

    Example:
    yourfavoriteeditor hello.c
    gcc -o hello hello.c
    ./hello
     
  3. macrumors newbie

    briankkatz

    Joined:
    Oct 19, 2011
    Location:
    5220 Summer Cres, Virginia Beach, VA 23462
  4. macrumors member

    Joined:
    Jun 4, 2009
    #4
    There is nothing wrong with gcc but can I recommend you try out clang as well. The usage is almost identical but as a new user you might find the warnings and errors a bit easier to deal with. You should try turning on some extra warnings as well so the compiler gives you some hints about possible errors. So instead of:

    try:

    clang -Wall -o hello hello.c
     
  5. macrumors 601

    talmy

    Joined:
    Oct 26, 2009
    Location:
    Oregon
    #5
    Yep, use Clang. I had replied with the "generic answer" but have been using Clang myself. Superior error and warning messages wrt GCC.

    I'll also add that anyone spending any time compiling from the command line should learn to use make. Every C program I work on (and there are lots) is built using make.
     

Share This Page