Articles‎ > ‎Technical Articles‎ > ‎

Compile and Run simple C Program with gcc Compiler in Ubuntu Linux

posted Feb 24, 2012, 4:22 AM by Thiyagaraaj M   [ updated Feb 24, 2012, 4:42 AM by Thiyagaraaj Mp ]

Step 1: Check gcc Version

  • Open terminal in Ubuntu
ubuntu@ubuntu-machine:~$ gcc --version
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Step 2: Open Text Editor

  • Open gedit with GUI (or) ubuntu@ubuntu-machine:gedit
  • In Terminal Type gedit and enter.(Note : Now you get gedit editor)

Step 3: Simple C Program

  • Now You type these Program and Save Desktop, file named as example.c
#include <stdio.h>
int main(void)
{
printf("This website Name is www.thiyagaraaj.com\n");
return 0;
}
  

Step 4: Check C File

  • Open New Terminal and Type ls
ubuntu@ubuntu-machine:~$ ls
Desktop glassfish-3.1.1 NetBeansProjects tmp
Documents Image Pictures
Downloads Music Public 
         
  • Now Move Desktop with these command 
ubuntu@ubuntu-machine:~$ cd Desktop

Check C File

ubuntu@ubuntu-machine:~/Desktop$ ls
example.c

Step 5: Compile C Compiler

  • Complie C Program with gcc compiler
ubuntu@ubuntu-machine:~/Desktop$ gcc example.c
  • Now C Program Compiled

Step 6: Check Execute File

ubuntu@ubuntu-machine:~/Desktop$ ls
a.out  example.c  example.c~

  • Here a.out is execution format of the example.c file
  • Now Execute a.out
ubuntu@ubuntu-machine:~/Desktop$ ./a.out

Sample Output:

This website Name is www.thiyagaraaj.com