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

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

  1. macrumors newbie

    #1
    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.

    ie/

    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

    ^o

    and save file "hello.c"

    now back to terminal still in file hello.c

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

    output:

    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

    balamw

    Staff Member

    #2
    right before you try
    Code:
    gcc -Wall -Werror -O -o hello hello.c
    please type
    Code:
    pwd
    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.

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

    macrumors 6502a

    #3
    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 : http://ftp.gnome.org/pub/GNOME/binaries/mac/gedit/3.2/
     
  4. macrumors newbie

    #4
    hello.c helloworld.c

    123.c:
    iapple

    hellohello.c:
    123.c hellohello.c

    iapple.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.

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

    macrumors 6502a

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

    Code:
    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 :

    /Users/test/Desktop/hello.c
     

    Attached Files:

  6. Moderator

    balamw

    Staff Member

    #6
    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.

    B
     
  7. macrumors newbie

    #7
    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