Saturday, February 19, 2011

How do we Run a C program in linux...

First create a file.c, obviously having a C code.
/* FILE: test.c */
#include <stdio.h>
void main()
{
    printf("Hi!!!!!!!!!");
}
Go to terminal.
We assume this file.c is on desktop.

Test the file with
cd Desktop
ls file.c
It will echo the filename if succeeded.

Now type
gcc -Wall file.c
On succes, it returns the command prompt.
like
sujit@sujit-desktop:~/Desktop$ ls test.c
test.c
sujit@sujit-desktop:~/Desktop$ gcc -Wall test.c
sujit@sujit-desktop:~/Desktop$

to run the file type
chmod +x a.out
the output will be displayed.
Here a.out is the executable file created, which runs the executable code of your program. In Windows .obj file is created. My observation is, linux creates .out file which is directly executable. This must be the difference in Windows[;(] and Linux[:)].

The full guide to use gcc is available at


http://ubuntuone.com/p/e9f/






 

No comments:

Post a Comment

Ubuntu Wallpaper of the Day