LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   hwo to execute C programs in linux (https://www.linuxquestions.org/questions/programming-9/hwo-to-execute-c-programs-in-linux-31399/)

gonus 09-28-2002 04:30 PM

hwo to execute C programs in linux
 
I just started using my new sams teach yourself c in 24 hours book. It's great but one problem is it doesn't explain how to execute c programs in linux. I can compile what ever I do, but how do I execute it so I can get the output?

thanx

Gonus

Ztyx 09-28-2002 04:37 PM

To compile:
gcc -o output_file my_source_file.c

To run:
./output_file

acid_kewpie 09-28-2002 04:37 PM

when you've compiled the program, just run it with

./programname

if you've not set a name, it'll normally be called a.out

gonus 09-28-2002 08:53 PM

ok. its name is a.out to compile and have it named somethingelse

gcc -o somethingelse hello.c

then to run

./somethingelse

is that correct? Will a.out still run?

thanx

Mentecapto 09-29-2002 01:22 AM

The commands you just wrote will get you a program named 'somethingelse'. There will be no a.out. To run your program, just type ./somethingelse , as the others said :).

gonus 09-29-2002 11:37 AM

Thank you.

Gonus

purpleburple 09-30-2002 05:44 AM

after typing out your source code in an editor such as vi or emacs just save the file as 'programname.c' then compile it with

gcc -o programname programname.c

then run it with

./programname

:)

GtkUser 09-30-2002 04:20 PM

Why not make it simple:

gcc progname.c
./a.out

acid_kewpie 09-30-2002 04:46 PM

i'm lost now... the last two posts have just repeated the same things that have already been said... :confused:

Mara 09-30-2002 05:54 PM

Not exactly... One used -o option. It allows you to specify the name of resulting file. If there's no -o option, a.out is created.
<Edit> Whoops.. I've written it after reading 3 last posts...</Edit>


All times are GMT -5. The time now is 05:18 PM.