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
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.