Compile & Run C Program on Linux Terminal



1) Write any C program in text editor and save as filename.c
In following example, I have saved this file on my Desktop.

2) To run this program, you have to compile it first.
$ gcc -o compiled-filename /home/user/Desktop/filename.c 
Where compiled-filename is the name of compiled file, it can be anything.
This will generate a compile copy of your program as a name compiled-filename in same directory where you ran the above command.

3) Now create output copy of your program.
Following command generate a output file of your program in same directory.
$ gcc /home/user/Desktop/filename.c
4) Now run your program.
$ ./a.out 
 or 
$ ./compiled-filename
where a.out is output copy of your program.
Alternatively you can run compiled copy of your program.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...