CMPT 212
Object-Oriented Applications Design in C++
Spring 1998
Lecture 5
Wednesday, January 14, 1998
Dependencies (continued)
When we build a program, we compile every source file then
link the object files together to produce an executable file.
In the example above, we would compile one.cpp,
two.cpp, and three.cpp, then link
one.obj, two.obj, and three.obj
to produce program.exe.
When we make a program, we only compile the source files
which have changed or which depend on files which have changed.
If any object files have changed (either before the make or during
the make), we link the object files to produce the executable file.
In the example above, if we changed two.cpp and then
did a make, we would compile two.cpp then link
one.obj, two.obj, and three.obj
to produce program.exe.
If we changed three.h, we would compile two.cpp
and three.cpp then link all of the object files.
If we changed two.obj, we would just link all the
object files.
Question: how do we tell if a file has been changed?
Normally we use the "last changed" time stamp of the file.
If file X depends on file Y and the
time stamp of Y is later than the time stamp of
X, then we assume that X must be
reprocessed.
Example: one.h contains a definition of a data type
that is used in two.h.
When one.cpp (or two.cpp) is compiled,
one.h is included twice.
If the header file only contains function prototypes, it can
safely be included more than once. But type or class definitions
cannot appear more than once.
Solution: use #ifndef and #define preprocessor
directives.
The #define directive defines a value for the
preprocessor.
The #ifndef directive causes the preprocessor to
allow the compiler to compile a section of code only if a
value has not been defined. (There is also a #ifdef
directive.)