c programming on terminal

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

  1. manee
    Expand Collapse
    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. talmy
    Expand Collapse
    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. cqexbesd
    Expand Collapse
    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
     
  4. talmy
    Expand Collapse
    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