Help beginner programer, can't get my terminal to compile.

Discussion in 'Mac Programming' started by sg001, Jul 30, 2012.

  1. macrumors newbie

    Hi could someone please have a look at the following steps to see if there is something I'm missing.

    1/ I have d/lded xcode (current) and installed command line tools.

    2/ for some reason edit is not opening in my terminal window.

    ie I type "gedit hello.c"

    output:- bash:gedit: command not found

    but I just use pico and it seams to work i.e.

    "pico hello.c"

    and it opens a pico editing window.

    secondly the compiler does not seem to work in terminal.


    i create a new file "mkdir hello.c"

    "cd hello.c"

    now i am in hello.c

    next step

    "pico hello.c"

    and i type this simple code

    #include <stdio.h>

    int main(int argc, char * argv[]){

    printf("Hello World!\n");
    printf("Goodbye World!\n");
    return 0;

    now I save by


    and save file "hello.c"

    now back to terminal still in file hello.c

    "gcc -Wall -Werror -O -o hello hello.c"


    i686-apple-darwin11-llvm-gcc-4.2: hello.c: No such file or directory
    i686-apple-darwin11-llvm-gcc-4.2: no input files"


    This is really annoying me I feel I have tried everything

    please please help. Thanks
  2. Moderator


    Staff Member

    right before you try
    gcc -Wall -Werror -O -o hello hello.c
    please type
    ls *.c
    and post the results here it doesn't look like you are in the right working directory when you issue the gcc command.

  3. kryten2, Jul 30, 2012
    Last edited: Jul 30, 2012

    macrumors 6502a

    Gedit is the official text editor of the GNOME desktop environment. It doesn't come standard on OS X. You can get/compile it yourself with MacPorts, Homebrew or other alternatives.
    Gedit Mac OS X packages :
  4. macrumors newbie

    hello.c helloworld.c


    123.c hellohello.c


    pls note I have tried doing this with a few different file names as I have tried to get it working a few times.

  5. kryten2, Jul 30, 2012
    Last edited: Jul 30, 2012

    macrumors 6502a

    Open Terminal and cd into your directory where your .c file is and type :

    gcc -Wall -Werror -O -o hello 
    then press tab to see if you see your hello.c file. If you do see it press h and tab again. Bash will autocomplete.

    balamw asked for the result of the pwd command. The result will be a POSIX style path using the slash / as the separator for directories eg /path/to/some/folder.

    Example :


    Attached Files:

  6. Moderator


    Staff Member

    You're not helping yourself by giving your folders the same name as source files. In general that can be a bad idea. If you want to reinforce that the folder has a C file in it, you could call it "hello_c" but don't call it "hello.c" that is a surefire path to confusion.

  7. macrumors newbie

    Ok I figured it out now thanks for the help.

    I think thats what I was confused about.. I thought the folders had to be the same name as the c file.

Share This Page