Home » C Programming » Tutorial » Compile C in GCC Compiler
Compile C Program using GCC compiler (linux)
The GNU Compiler Collection is a compiler system produced by the GNU Project supporting various programming languages. C is one of the programming language which is supported by GCC compiler.
Steps to compile & execute C program
1. Create file helloworld.c using vi editor
VI editor is commonly used editor on Linux. There few more editors like VIM, Gedit which can be used to edit files. To use VI editor, launch the terminal on Linux and type "vi helloword.c" & press enter.
2. Now press "i" for insert mode and write basic hello world program.
![Open C file in vi editor](images/open-c-file-in-vi-editor.png)
3. Save the file using command ":wc" and compile it
Compile it using gcc command i.e "gcc helloworld.c", a.out file is created as output file.
![Write C code in vi editor](images/edit-c-source-code-in-vi-editor.png)
![gcc command to compile c code](images/gcc-command-to-compiler-c-code.png)
![running a.out file](images/running-executable-on-linux.png)
![Open C file in vi editor](images/open-c-file-in-vi-editor.png)
![Adding newline character to C program](images/use-new-line-character-to-show-data-in-new-line.png)
![Executing a.out file produced by gcc compiler](images/execute-out-file-after-compilation.png)
Output of the program
The default output file produced by GCC is a.out, We can pass argument -o to give any name.
Specifying the output file name
![Open C file in vi editor](images/specifying-the-output-filename-in-gcc-command.png)
NOTE - if there are more number of filse then it is good practice to compile the source code using Makefile
Video Compilation of C Programming using gcc compiler on Linux
C Tutorial
- History of C Language
- The First Program in C
- Compilation & Execution
- Compile C on Dev-C++
- Compile C on GCC Linux
- Variable & Data types
- Comments
- Storage Classes
- Conidtional Statements
- Switch Cases
- Loops (for, while, do-while)
- Arrays
- Pointers
- Function Pointer
- Strings & Library func
- Formated I/O
- Structure
- Enum
- Union
- File I/O
- Memory Management
- Error Handling
- Type Casting