compilation and linking process in c

Include file
Header file
Your source code can use some functions and variables for which the source code is not in the file. For instance it might use printf to write to the screen. The way this is handled is to have a file or files which provide definitions for those other things it might use. For instance, it might provide a function prototype which defines what the function printf is like.

These files are called header files or include files. The files are text files written in the C or C++ language. The header file or files are bundled into the source code by a statement like this:

#include <stdio.h>

When the compiler begins to run it first runs a preprocessor phase. During that phase the text from the header files are inserted into its image of your source file at the point where the #include statement is found.

During the next phase, the compiling phase, it sees the result of that preprocessor phase. What was in the header files appears as if it were part of the source file.

Object file
Compiling
A compiler takes your file containing source code and translates it to machine code. It then places that machine code into an output file called an object file and has the file extension .obj.

Each of the items your files provides or needs has a name, a symbol. The object file also has lists of those symbols that your code provides and of those symbols which it needs. The process of translating the source code into an object file is called compiling.

compilation and linking process in c

Linking

After the compiler has created all the object files, another program is called to bundle them into an executable program file. That program is called a linker and the process of bundling them into the executable is called linking.

The linker looks at all the object files you have told it to use.

It assembles two lists,

– the list of publics
Items found in the object files. These are items which are provided by those files

– the list of unresolved externals
Items the object files say they need but do not have

It then examines the object files, finding the publics and placing their addresses into unresolved externals until all needs are satisfied. At that point it has what it needs to create a binary file containing the whole program. This binary file is the executable file, the program, and normally has the file name extension .exe

 

 compilation and linking process in c

To gain more knowledge about hardware and software just click here

You can share your feedback (both positive and negative) by mailing to [email protected]. It will help us to improve our site.We will respond your mail within 24 hours.