Department of Computer Science
Next: Linkage and consistency
Up: Program structure, separate compilation
Previous: Interfaces and implementations of
With separate compilation the order of compilation
is important to ensure that (1) compiled versions
of the interface information are available (in the case
of Eiffel, Java and Ada), and (2) client code is
compiled using the most recent versions of units, and also will be
re-compiled if they change.
- Programmer managed compilation
- The programmer must ensure that all the files
are compiled in the correct order and that if an
interface is altered then all the clients
that depend on that interface must be re-compiled.
- make utilities
- The dependencies between interface, implementation and
client code files can be defined and then compilation and linkage
commands can be included, these will be executed if
make finds that any files are out of date with
respect to the define dependencies.
So for example if the C++ class List is defined
in list.h, its implementation code is in list.cc,
and a client program is in uselist.cc then the
following Makefile could be used:
list.o: list.cc list.h
g++ -c list.cc -o list.o
uselist.o: uselist.cc list.h
g++ -c uselist.cc -o uselist.o
uselist: list.o uselist.o
g++ uselist.o list.o -o uselist
this says that, for example, uselist.o must be re-made if
uselist.cc or list.h change, and the
command to do it is:
g++ -c uselist.cc -o uselist.o
The other dependencies are similar. In practice make files
are much simpler because a lot of the dependencies can be inferred.
If the program make is run it will use
the Makefile to check the creation times
of all the files and see if any need re-making.
The utility make can be used for any language.
Some Ada and Modula2 implementations have their own
adapted versions of make that are simpler
(but less flexible) because they are language specific.
- Integrated compilation systems
- Some compilers for some languages take
all the reponsibility for separate compilation. The
programmer defines a project and gives it the
file names. Then the system will
automatically infer the dependencies by scanning files
and then compile as needed.
In nearly all cases there is a hidden ``make'' behind
the scenes.
The Visual C++ and Borland C++ compilers are like this,
so are nearly all Eiffel compilers.
Next: Linkage and consistency
Up: Program structure, separate compilation
Previous: Interfaces and implementations of
Page generated: 2002-11-04 by Bob Dickerson
© University of Hertfordshire Higher Education Corporation (1998)
Disclaimer