Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm migrating to from Windows to Linux and I heard a lot about Linux and how you can do some real good programming under Linux. But I'm have no idea about how to compile a code written in C on Linux.

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

Compile your source file prog.c with:

 $ gcc prog.c

this will generate an executable named a.out. Execute it with:

 $ ./a.out 

To specify the name of the executable during compilation:

 $ gcc prog.c -o prog

execute with:

 $ ./prog

gcc is also the C++ compiler. There are plenty command line options available, so it's worth getting to know the man page.

Here is the manual for the most recent version of the compiler.

share|improve this answer
add comment

Find a tutorial on the Gnu Compiler Collection and read it all trying examples on an hello world program. Make obvious errors to get used to the error messages that it spits out and look them up. There is a wealth of knowledge online about different messages. You can copy and past them into google and find good results.

A good book would be (An Introduction to GCC) by Brian Gough :ISBN 0-9541617-9-3:

One thing you should always include in compiling is the -Wall flags(the W is in caps). It tells gcc to spit out the most common error messages.

geany is the text editor I uses as it is light weight fast and includes just about anything you could need in an IDE.

After you get used to gcc check out make as they go hand in hand for projects. What make does is provide a way to compile everything with out having to remember what libs need to be manually included for linked on compile time form the terminal. It also makes you life easier and easier as a project gets more complicated.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.