queens.c,
checkboard.c,
printboard.c,
queens.h.
We want to be able to compile the pieces of the program separately, but the danger demonstrated by the first pass is that it is all too easy to get the pieces out of sync with each other.
The first part of the solution is to create a header file, queens.h, which will contain all of the definitions that should be shared amongst the separate source files.
#define
's,) typedef
's, struct
definitions, and function prototypes.
#include "queens.h"
#include
lines.
To compile the program, we can either compile each of the source files
separately,
gcc -c queens.c
gcc -c checkboard.c
gcc -c printboard.c
gcc -o queens *.o
Or we can compile and link them all at once.
gcc -o queens *.c
But this is still less than ideal. We want to be able take advantage of separate compilation; if we change the contents of the header file, but forget to recompile each of the source files, it is possible to still have stale object (.o) files sitting around.
Why doesn't someone write a tool to make this easier?