Compiler

Compiler

Compiler is a special computer program to convert the program code into machine language. When programmer writes a program like C++ program using an editor, it cannot directly run. To get output of the program we have to compile the program and run the appropriate language compiler. The program that programmer write called source code and compiled code produced by the compiler is usually called an “object file”. Predefined libraries combined the one or more files by a linker.
A library is a collection of pre-compiled “object code” that provides operations and functions that are done repeatedly by many computer programs.

Compiling and linking a C++ program

The program that you type into the Edit window constitutes the source file. When it is saved to disk, it is an ASCII file similar to that generated by word processor. It has the .CPP file extension. If you are not familiar with compiled languages, the process of transforming a source file into an executable program may seem rather mysterious.
Remember that a source file is not an executable program. It is only the instructions on how to create a program. Transforming your source file into an executable program requires two steps.
First, you must compile the source file into an object file. The object file, which has an OBJ extension, contains machine-language instructions that can be executed by the computer. However, these instructions are not complete. A second step, called linking, is required.
The linking step is necessary because an executable program almost always consists of more than one object file. Linking combines the object files into a single executable program.

Why does a program consist of more than one object file?

There are two major reasons. First, the programmer may have divided the program into several source files. Each of these source files is then compiled into a separate object file, and these object files must be linked together. Let us assume that our program consist a single source file. Second, the library routines we mentioned earlier come in object-file from and must be combined with the user-written program.
Thus turning your source file into an executable file is a two-step process. First you compile your source file into an object file, and then you link it with the necessary library routines. The following figure shows the relationship between compiling and linking. Let’s see how to use the IDE to compile and link your program.

Leave a Reply

Your email address will not be published.