Forum Home
Press F1
 
Thread ID: 22317 2002-07-17 21:46:00 C programming in Linux Shroeder (492) Press F1
Post ID Timestamp Content User
63195 2002-07-17 21:46:00 Looking at my first attempt at C programming.

Using the obligatory "Hello World" program (copied correctly)

I type it up using the pico editor, save it as hello.c

Exit pico and go into the bash shell

type

cc -o hello hello.c

(get no error messages)

hello is now a file in my directory but when I type "hello" at the prompt I get the no such program command (or whatever) exists <sorry, doing this bit from memory>

Tried also using

gcc -o hello hello.c

but with the same result.

No doubt I'm missing summat obvious so any help would be appreciated

Ta
Shroeder (492)
63196 2002-07-18 03:51:00 Shroeder,

use ./ in front of an executable when you are in the same directory.

the way around this is to add ./ to your $PATH variable (done in bash with export PATH=$PATH:./ )

Just to make it clear - you should be typing ./hello to execute this program.

good luck with your developments.
ctonks (746)
63197 2002-07-18 03:54:00 Aha.

Yes, it is obvious. ;-) Do ls -l hello and you will spot it in the list of attributes. That file hasn't got the "x" (executable) attribute set. Do chmod +x hello and it will work.

You are not stupid. It has caught everyone. :D There are no execptions.
Graham L (2)
63198 2002-07-18 05:12:00 Thanks you two :)

Out of interest, should I use cc or gcc

and should they give a message only in the event of error compiling (ie. if it works, then it simply goes to a fresh prompt without comment?)

Thanks again
Shroeder (492)
63199 2002-07-18 05:39:00 cc is gcc. (It will be a logical link).

Linux follows the Unix original form for messages: "No news is good news". If you had ever used a Teletype ASR33, you would know why. That's also the reason for the 2 letter command names.
Graham L (2)
63200 2002-07-18 05:46:00 Ta

:D

B-)
Shroeder (492)
1