PDA

View Full Version : Help beginner programer, can't get my terminal to compile.




sg001
Jul 30, 2012, 06:00 AM
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



balamw
Jul 30, 2012, 06:05 AM
right before you try gcc -Wall -Werror -O -o hello hello.c please type 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

kryten2
Jul 30, 2012, 07:56 AM
for some reason edit is not opening in my terminal window.
ie I type "gedit hello.c"

output:- bash:gedit: command not found


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/

sg001
Jul 30, 2012, 08:01 AM
right before you try gcc -Wall -Werror -O -o hello hello.c please type 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

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.

kryten2
Jul 30, 2012, 08:24 AM
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 :

/Users/test/Desktop/hello.c

balamw
Jul 30, 2012, 09:22 AM
pls note I have tried doing this with a few different file names as I have tried to get it working a few times.


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

sg001
Jul 30, 2012, 11:18 PM
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

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.