Program Preparation: Coding and Programming in C++ Language II (7261-229) - Program Preparation
Program Preparation: Coding and Programming in C++ Language II (7261-229) - Program Preparation
PROGRAM PREPARATION
Aims
Large programs consist of many hundreds of source files. If they had to all be
re-compiled whenever a change took place development would be a very
slow process. Instead compilers produce intermediary files (termed object
code) - one object file for every source file which are linked to produce
executable code. If a source file changes the compiler will only translate that
one file, producing a new version of the corresponding object file. By linking
the new object file with the existing ones a new executable is obtained.
Programs may consist of many source files, consequently they must all have
meaningful names which help other developers to understand what purpose
that file serves.
It is mandatory for all C++ source files to have the extension .cpp which
indicates to the compiler that it is dealing with a C++ source file.
To aid developers the intermediary object files produced by the compiler have
the same file name as the source file but a different extension, this time .obj
The executable code that is eventually produced by linking all the object files
together is written to a file with a .exe extension.
Many tasks that developers wish to perform have already been done by
others. To save effort for programmers the compiler writers have written may
useful standard functions, for example displaying text on a screen, obtaining
user input from a keyboard, sorting text into alphanumeric order, etc.
The compilers linking stage has already been introduced as the point when all
the object files present in a project are combined together to generate
executable code. This stage is also responsible for linking in any libraries
required by the source code.
There are many different compilers, each having their own sets of commands
to compile source files and link object files to produce executable files, but
essentially they all follow the same set of operations.
First the pre-processor will work through the source code, making
appropriate modifications. Once complete the compiler will convert the source
into object code. The linker will then step in to combine all the object files and
libraries together into an executable program. Depending on options chosen
during the compilation and link stage the resultant program will either be stand
alone or reliant on the libraries used being available at run-time. Stand alone
programs contain copies of all the libraries used within them, so although
being more transportable than the library dependent types they will also be
much larger. Note, a few compilers exist that do not permit the generation of
stand alone programs - the executable code they generate always needs the
support of run time libraries.
Source File
Compiler
Executable file