LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-11-2006, 11:55 AM   #1
hardstyleFX
LQ Newbie
 
Registered: Sep 2005
Location: Estonia
Posts: 27

Rep: Reputation: 15
Compiling a single source file:


Hello!

I Would like to know how to compile a single source file using GCC.
I have written programs in Windows, but in the future I want to do that in Linux.
 
Old 01-11-2006, 12:19 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Code:
gcc -o EXECUTABLE file.c
 
Old 01-11-2006, 01:01 PM   #3
hardstyleFX
LQ Newbie
 
Registered: Sep 2005
Location: Estonia
Posts: 27

Original Poster
Rep: Reputation: 15
Thanks alot.
 
Old 01-12-2006, 05:01 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
or:
(e.g: example.c)

make example

hint: don't call files 'test' there's a command of the same name.
 
Old 01-12-2006, 05:19 AM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by Matir
Code:
gcc -o EXECUTABLE file.c
Suggest to add the -Wall option
Code:
gcc -Wall -o EXECUTABLE file.c
Quote:
Originally Posted by bigearsbilly
or:
(e.g: example.c)

make example

hint: don't call files 'test' there's a command of the same name.
Does not work if he does not have a makefile
Your hint is correct, it fooled me a couple of times

Last edited by Wim Sturkenboom; 01-12-2006 at 05:20 AM.
 
Old 01-12-2006, 05:29 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Quote:
Originally Posted by Wim Sturkenboom
Does not work if he does not have a makefile
I'm sorry Wim, but I'm afraid you are WRONG.
Implicit make rules are in force.

as I said

make example will work
observe:
Code:
touch example.c
make example
cc     example.c   -o example
 
Old 01-12-2006, 06:05 AM   #7
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
Never to old to learn
 
Old 01-12-2006, 06:09 AM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
surprising how few people know about it!
It's dead useful
 
  


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
C++ Compiling single class without a main() harshnoise Programming 4 08-29-2005 04:59 PM
trouble compiling xmms mp4 plugin from source: "no such file.." mayasedai Linux - Software 3 02-01-2005 11:13 AM
Cross Compiling from Single Proc to SMP mikeyt_333 Linux - Software 2 07-12-2004 06:57 AM
compiling software from source...how do i delete the folder w/ source? webazoid Linux - Software 2 07-01-2004 09:09 PM
Parse error returned when compiling a source file with Kdevelop spilios Programming 1 09-09-2003 06:00 AM

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

All times are GMT -5. The time now is 04:06 AM.

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