Compiling C Programs


We usually use a compiler with a graphical user interface, to compile our c program. this can also be done by using  cmd. the command prompt has a set of steps we need to perform in order to execute our program without using a GUI compiler. 

Editing 

The first step in developing an application in C is to write/edit the source code. The source code contains all the instructions which needs to be executed by the machine in a text format (understandable by humans).

We can use either a plain text editor (e.g. Notepad) or the editor provided by the IDE. The source code must be written as required by the C language syntax. After the source file is ready, it must be saved as a *.c file.



Compiling

The next step is to compile the program. To do this we need to use the command gcc followed by the name of the program we are going to execute. In our case, we will use Armstrong.c.

Output - How to Compile C Program In CMD - Edureka

After this, an executable file will be created in the directory that your c file exists in. Eg: Armstrong.exe

linking

The link phase is implemented by the linker. The linker is a process that accepts as input object files and libraries to produce the final executable program. Linking is the process of integrating library files into our program. Library files are prepackaged files that contain the definition of functions in machine language and have the extension .lib. The object (.o/.obj) file contains some unknown statements that our operating system cannot interpret. You can think of this as a book with some unfamiliar terms in it, and you’ll use a dictionary to figure out what they mean. Similarly, we use Library Files to provide explanations for some unknown statements in our object file. The linking process creates an executable file with the extension .exe in DOS and .out in UNIX OS.


Linking

Debugging

In the context of the C programming language, debugging refers to the process of identifying and correcting errors or bugs in your code. These errors can range from simple syntax mistakes to more complex logic issues. Debugging in C is essential to ensure that your program functions correctly and efficiently.


In conclusion, comprehending the compilation process in C is indispensable for developers aiming to write optimized, error-free, and efficient code. Each stage of compilation holds significance, from preprocessing to linking, in ensuring that the final executable runs seamlessly. Acknowledging the intricacies of this process empowers programmers to debug effectively, optimize code, and create robust applications.

Previous Post Next Post

Contact Form