Home Compiling n Executing Programs
mod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_counter
mod_vvisit_counterToday1
mod_vvisit_counterYesterday0
mod_vvisit_counterThis week1
mod_vvisit_counterLast week0
mod_vvisit_counterThis month1
mod_vvisit_counterLast month0
mod_vvisit_counterAll days4219

We have: 1 guests online
Your IP: : 38.107.179.230
 , 
Today: May 21, 2012

Tracker

visitors by country counter
flag counter

Compiling and Executing Programs written in C

The process of compiling and executing program is different in different systems. We discuss compiling and executing process in UNIX and DOS environments.
1.    Running in DOS
2.    Running in UNIX

1.    Running in DOS
First a C program is typed in a text file editor. This program is called source program. This program is converted to executable by compilation process. There are many vendors providing C compilers such as Turbo C, Turbo C++, Borland C++, C++ Builder, etc. Microsoft has produced Quick C, Visual C++, etc. Compilation can be done in two ways;
a). Using IDE and
b). Using command-line compiler.


a. Using IDE (Integrated Development Environment)
The IDE has all facilities to develop, run, and debug programs in a single environment. It has editor, compiler and debugger within itself. Let us see how to compile and run our first program display.c in Turbo C IDE environment. To start Turbo C IDE we run tc.exe on command prompt. Our program is typed in IDE and saved as display.c by choosing save from file menu or by pressing shortcut F2. Program is compiled by choosing compile from compile menu or by pressing shortcut alt+F9. If the program has syntax errors, the compiler will complain about errors. These errors are corrected and the same process is repeated again to compile and run the program. The compilation will create the executable program (display.exe in this case) which is actually executed.
Microsoft C also has similar type of environment too. The process is almost similar with different shortcut keys. As is it not the easily available compiler we focused on Turbo C.

b. Using Command-line compiler
Here also we focus our discussion on Borland and Microsoft command line compilers. The command line compiler for Turbo C is tcc.exe, Borland C is bcc.exe and Microsoft is cl.exe. The GNU command line compiler for DOS is gcc.exe. The command line compilers are invoked from the command line to compile the program. Let’s see how we compile and execute our first program display.c with the command line compiler of Turbo C.
Suppose the program is typed in any text editor and is saved as display.c. The following command will convert the program into executable program called display.exe.
C:\tc\bin\>tcc display.c
After the compilation process the program is executed as follows
C:\tc\bin\>display
To execute the program we don’t need to type the .exe extension. The executable program will act as a command.

2.    Running in UNIX
Every UNIX system and its GNU clone like LINUX has a C compiler with in itself. The C compiler in UNIX is cc, while the GNU systems (like LINUX) have gcc also.
First a source file is created using a text editor like vi or emax. The C program should be saved with .c extension. The extension is required for C compiler but not for UNIX. Our program display.c is compiled as
[user @ localhost]$ cc display.c
This command will generate binary file (executable) a.out. This program is executed as
[user @ localhost]$ ./a.out
The generated a.out is not a meaningful name for executable for a single user. We must supply appropriate name by supplying –o option while compiling the program.
[user @ localhost]$ cc –o display display.c
The command will generate display as binary file. This program is executed as
[user @ localhost]$ display
To include the mathematical library during compilation we include the –lm option. To compile the libfunc.c program which uses mathematical library the compilation is done as pile the libfunc.c program which uses mathematical library the compilation is done as
[user @ localhost]$ cc –lm –o libfunc libfunc.c

A lot of open source free IDEs like Anjuta, Kdevelop, VIDE, Ecplise are available for UNIX and UNIX like systems.