How to Compile a C Program Using the Gnu Compiler
The Gnu Compiler Collection (GCC) software allows you to compile software programs written in a range of computer languages, including C, C++ and Java. Since the software is a free and open source, you can easily obtain a copy and, if you're really ambitious, modify it to fit your programming needs.
Instructions
-
-
1
Get a copy of the GCC software and install it on your computer. The software and the documentation are freely available at the GNU website.
-
2
Write your software code in C (or choose one of the other supported languages). Let's say that your code is located in a file titled "Program."
-
-
3
Choose a correct file extension. GCC automatically compiles a program according to the language specified by the file extension. For the C language, use ".c" (as in "Program.c").
-
4
Select an output file name; you do not need to specify an extension. You may simply want your program to compile to the file name "Program."
-
5
Run the GCC software to compile your program. The command is "gcc -o Program Program.c" for compiling "Program.c" to an executable file called "Program."
-
6
Check the compiler output for errors. If you have bugs in your code that the compiler can't handle, you need to fix your code and go back to Step 5.
-
1
Tips & Warnings
There are a range of options associated with the GCC compiler. The more complicated the project, the more options you may need to invoke. Documentation of the GCC package is available at the GNU website.
If you don't specify an output file name in Step 4, you can compile your program with just the command "gcc Program.c." The GCC software will create an executable file with the name "a.out."