Home C C++ Java Python Perl PHP SQL JavaScript Linux Online Test

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

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
gcc command to compile c code
running a.out file
Open C file in vi editor
Adding newline character to C program
Executing a.out file produced by gcc compiler

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

NOTE - if there are more number of filse then it is good practice to compile the source code using Makefile