Help Compiling C Code

Discussion in 'Mac Programming' started by jackfrost9p, Sep 24, 2005.

  1. jackfrost9p macrumors newbie

    Joined:
    Sep 24, 2005
    #1
    I am new to programming and am trying to use my powerbook at school, which of course is dominated by pc's. I have written very simple code in C using vi in terminal, but i dont know how to compile or run my code. Thanks for the help!!
     
  2. peterparker macrumors regular

    peterparker

    Joined:
    Mar 12, 2005
    Location:
    Houston
    #2
    If you have gcc installed:

    gcc myfile.c -o myfile
     
  3. jackfrost9p thread starter macrumors newbie

    Joined:
    Sep 24, 2005
    #3
    well my file name is test.c
    and if i tpye in gcc test.c -o test

    i get this error

    -bash: gcc: command not found

    i dont know if this means i need to install gcc or not and if I do where can i get it thanks alot!
     
  4. peterparker macrumors regular

    peterparker

    Joined:
    Mar 12, 2005
    Location:
    Houston
  5. jackfrost9p thread starter macrumors newbie

    Joined:
    Sep 24, 2005
    #5
    where can i find the xcode
     
  6. peterparker macrumors regular

    peterparker

    Joined:
    Mar 12, 2005
    Location:
    Houston
    #6
  7. jackfrost9p thread starter macrumors newbie

    Joined:
    Sep 24, 2005
    #7
    well i dont have my disk and i am not a developer, is there any other way to do it. Thanks alot you have been very helpful!
     
  8. yg17 macrumors G5

    yg17

    Joined:
    Aug 1, 2004
    Location:
    St. Louis, MO
    #8
    Its free to become a developer. On the link he posted, there's a link to sign up. Once you do that then you can download Xcode
     
  9. Soulstorm macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #9
    Actually, you don't have to be a programmer by proffession to download x-code. I know I am not, I just gave some information and they let me download X-Code.

    Here is what you will do:

    Download X-Code and install it. Then make a new project. In the next dialog that appears you will see a selection of project types you wish to create. Choose "Carbon Bundle". That's it.

    In the window that appears, just write the code, compile it and run it. You don't have to use the terminal or any other debugger, X-Code is just what you need.

    I started just like that C++ programming.
     
  10. jackfrost9p thread starter macrumors newbie

    Joined:
    Sep 24, 2005
    #10
    Ok i did all that now how do i run the a.out file.

    Thanks
     
  11. seriypshick macrumors member

    seriypshick

    Joined:
    Apr 4, 2005
    Location:
    Everywhere
    #11
    Code:
    ./a.out
    ./ - means current dirrectory

    but here's a better (right) way to compile:
    Code:
    gcc test.c -o test
    then when it finishes compiling you type:
    Code:
    ./test
    instead of:
    Code:
    ./a.out
    a.out is a default program name if you don't specify what you wnat your program to be called

    Good luck.
     

Share This Page