LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-25-2007, 09:15 PM   #1
oliviapesayco
LQ Newbie
 
Registered: Jun 2007
Posts: 10

Rep: Reputation: 0
Help in C programming in Linux


Hi there.

I just wrote my first C prg in Linux (let's call it sample.c).... How can I compile it?

Thanks.
 
Old 06-25-2007, 09:26 PM   #2
PatrickNew
Senior Member
 
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
try this:
Code:
gcc -o sample sample.c
it will call the ("gcc") compiler and instruct it ("-o sample") to build the program "sample" from the source code "sample.c".
 
Old 06-25-2007, 09:39 PM   #3
oliviapesayco
LQ Newbie
 
Registered: Jun 2007
Posts: 10

Original Poster
Rep: Reputation: 0
Hi Patrick. I tried the gcc command you suggested, there are no errors and it built the program called sample. however, when I excute sample from the prompt it tells me that "sample: command not found"... I do not see the object file though, should it create a file called "sample.o"? Thanks.
 
Old 06-25-2007, 09:46 PM   #4
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,235

Rep: Reputation: 302Reputation: 302Reputation: 302Reputation: 302
./sample

if you are in the same directory
 
Old 06-25-2007, 09:50 PM   #5
oliviapesayco
LQ Newbie
 
Registered: Jun 2007
Posts: 10

Original Poster
Rep: Reputation: 0
Ok, that helped. thanks Dive

Ok, that helped. thanks Dive
 
Old 06-26-2007, 08:04 AM   #6
dasy2k1
Member
 
Registered: Oct 2005
Location: 127.0.0.1
Distribution: Ubuntu 12.04 X86_64
Posts: 958

Rep: Reputation: 35
the reason that you dont see the .o files or all the other stuff usially created with a compiler is that GCC by default ether pipes output between processes or deletes the files afterwards,

if you need the filles for somthing there is an option to keep them

try man gcc for more details
 
Old 06-27-2007, 05:19 AM   #7
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Code:
gcc -c ...
is for just compiling .c files into .o (no linking).

Code:
gcc -o prog ...
will compile the code if needed and then link it together into the program.
You can give both .c files (that will be compiled) and .o files
(previously compiled) as input for the linking.

Note that the "-o prog" is optional. If you don't specify the name of the output program that is to be created, it will be named "a.out" by default.

I suggest you read up on Makefiles and the "make" command too.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
New Forum for Linux-Gurus[Programming/Administration] or Linux-Advanced Users [ Progr raees LQ Suggestions & Feedback 5 04-12-2005 07:35 PM
Exp. Windows/Linux-Script Programmer - Need Linux Programming Mentor! ruttiger Linux - Newbie 2 10-28-2001 11:00 AM


All times are GMT -5. The time now is 10:24 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration