Recall:
Machine language instructions (ML) are the only instructions the processor/CPU can execute.
ML is just numbers. When the ML is put into memory, it can be fetched, decoded and executed by the processor. Different numbers will cause the processor to perform different actions.
Different type of processors usually have different ML's
Assembly language (AL) is a symbolic representation of ML.
A translation of the C++ program statements to machine language is necessary.
A number of steps are involved in the compilation process.
other ML ----+
V
+--------------+ +----------+ +-----------+ +--------+
C++ -->| PREPROCESSOR |-->| COMPILER |-->| ASSEMBLER |-->| LINKER |-->
Program +--------------+ +----------+ +-----------+ +--------+
Output: Modified C++ Assembly Executable "Complete"
program (copy) language code (ML) Executable
PREPROCESSOR |
The source program undergoes modification before it is compiled. A modified copy of the original program is created, however it is still valid C++. Things the preprocessor does includes:
|
COMPILER |
The C++ statements are converted into AL statements. |
ASSEMBLER |
The AL statements are converted into ML called object code. |
LINKER |
Object code from multiple sources is combined together to form a complete executable program. For example the ML to perform input/output is almost always linked in since most programs do input or output. |
Linking is an important phase of the compilation process.
All machine language can be compiled into a single executable program. This is called static linking. More common today is dynamic linking. With dynamic linking the "other" machine language remains separate and the linker arranges for your program to connect to the "other" machine language. Typing, at the prompt:
ldd executable_file_name
will show the dynamic libraries (files) the program requires. Try a.out
for the executable_file_name.
When the program name is typed at the prompt the command interpreter, usually called the shell, causes the operating system to load the program into memory and begin executing it.
Note that the whole process is also called compiling and gets its name from the subpart, the conversion from C++ to AL.
clang++
Compiling Options
|
Compile file file.cpp and create an executable named a.out |
|
Compile file file.cpp, create an executable, and name the executable file2 instead of a.out |
|
Output warnings |
|
Run the first 3 stages, but not the linker. |
|
Run the first stage of the compiler, the preprocessor, only. |
|
Show header file inclusion only. |
|
Output the version of |