|
The content of the various files are as follows:
f1.c | f2.h | f2.c |
---|---|---|
#include <stdio.h> #include "f2.h" int main( int argc, char *argv[] ) { double a, b; a = 4.0; b = square( a ); print( a ); print( b ); } |
void print ( double x ) ; double square( double x ) ; |
#include <stdio.h> #include "f2.h" void print ( double x ) { printf("Number = %lf\n", x ); } double square( double x ) { double r; r = x * x; return ( r ); } |
gcc -c f1.c (f1.c ---> f1.o) gcc -c f2.c (f2.c ---> f2.o) gcc -o main f1.o f2.o (f1.o, f2.o ---> main) |
We can easily discern the following file dependencies:
1. f1.o: f1.c 2. f2.o: f2.c 3. main: f1.o f2.o |
However:
|
Therefore, the actualy file dependencies are:
1. f1.o: f1.c f2.h 2. f2.o: f2.c f2.h 3. main: f1.o f2.o |
main: f1.o f2.o # We usually put the final target first gcc -o main f1.o f2.o f1.o: f1.c f2.h gcc -c f1.c f2.o: f2.c f2.h gcc -c f2.c |
How to run the program:
|
|