LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-28-2002, 04:30 PM   #1
gonus
Member
 
Registered: Apr 2002
Location: Huntsville, Alabama
Distribution: Ubuntu 9.04
Posts: 445

Rep: Reputation: 30
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
 
Old 09-28-2002, 04:37 PM   #2
Ztyx
Member
 
Registered: Dec 2001
Location: Stockholm, Sweden
Distribution: Ubuntu, Kubuntu and Debian
Posts: 338

Rep: Reputation: 30
To compile:
gcc -o output_file my_source_file.c

To run:
./output_file
 
Old 09-28-2002, 04:37 PM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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
 
Old 09-28-2002, 08:53 PM   #4
gonus
Member
 
Registered: Apr 2002
Location: Huntsville, Alabama
Distribution: Ubuntu 9.04
Posts: 445

Original Poster
Rep: Reputation: 30
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
 
Old 09-29-2002, 01:22 AM   #5
Mentecapto
LQ Newbie
 
Registered: Sep 2002
Posts: 8

Rep: Reputation: 0
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 .
 
Old 09-29-2002, 11:37 AM   #6
gonus
Member
 
Registered: Apr 2002
Location: Huntsville, Alabama
Distribution: Ubuntu 9.04
Posts: 445

Original Poster
Rep: Reputation: 30
Thank you.

Gonus
 
Old 09-30-2002, 05:44 AM   #7
purpleburple
Member
 
Registered: Jun 2002
Location: USA
Distribution: Slackware8.1
Posts: 332

Rep: Reputation: 30
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

 
Old 09-30-2002, 04:20 PM   #8
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
Why not make it simple:

gcc progname.c
./a.out
 
Old 09-30-2002, 04:46 PM   #9
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
i'm lost now... the last two posts have just repeated the same things that have already been said...
 
Old 09-30-2002, 05:54 PM   #10
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
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>

Last edited by Mara; 09-30-2002 at 05:56 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can xmodmap be used to execute programs? vexer Linux - General 1 10-02-2004 06:26 PM
Root can execute programs lawrencegoodman Linux - Newbie 11 01-28-2004 07:42 AM
Hwo to set up a VPN with linux asadhussain Linux - Networking 3 11-30-2003 06:48 PM
Programs execute at startup Greg21 Linux - Newbie 5 06-05-2003 03:07 PM
hwo do I install programs that are not RPM's gonus Linux - Newbie 14 06-02-2002 07:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration