Suppose you had a C program to add two numbers. Also suppose that the function that did the addition was in one C source file, and the function that called the adder was in another C source file.
You might have:
/*--------------------------------------------------------------*/ /* sum.h */ int sum(int x, int y);
/*--------------------------------------------------------------*/ /* main.c */ #include <stdio.h> #include "sum.h" int main(void) { int a = 3; int b = 4; int c; c = sum(a, b); printf("Sum of %d and %d is %d.\n", a, b, c); }
/*--------------------------------------------------------------*/ /* sum.c */ #include <stdio.h> #include "sum.h" int sum(int x, int y) { int result; result = x + y; return result; }
To build this program, you might do:
cc sum.c main.c -o my_sum
Or, to compile and link separately:
cc -c sum.c cc -c main.c cc sum.o main.o -o my_sum
Each time you made a change to sum.h, main.c or sum.c, you would re-type these commands.