Now assume that we want to change the implementation of the faculty and fibonacci functions so that the computations are done iteratively instead of recursively.
Figure 5: my_math.c: iterative implementation of the module
my_math.
Now we want to compile as few source files as possible. We therefore draw a dependency graph as shown in Figure 6.
Figure 6: Dependencies in our example. White boxes are source files, black
boxes are generated files.
The dependency graph shows which file should be regenerated
if one or more header or implementation files change.
It matches the #include
structure of our program very closely.
Only the #include <stdio.h>
is omitted, as is the dependency
a.out
libc.a
, while we assume that the standard
library and include files seldom change.
From the graph we derive that changing my_math.c
affects
my_math.o
and facfib
.
We therefore have to recompile my_math.c
and relink the object
files.
It is not necessary to recompile main.c
, because main.o
does not depend on my_math.c
.
We can do this manually by typing:
gcc main.o my_math.o -o facfib