Compiling with Multiple Files
This material is in section 12.3
Header files.
Guards
#ifndef SOMETHING #define SOMETHING c++ code here #endif
Prevents multiple definition of the objects
SOMETHING should not start with a _
Other things the "library" will provide to the outside world
Type definitions.
Constant definitions
function prototypes.
Any include files to define types needed for the above.
But not
Source code.
And possibly not
using namespace std;
Implementation file
Include the header file in quotes, not angle brackets.
#include "myheader.h"
implements everything promised in the header file.
Could have auxiliary routines not in the header file.
Compile with
-c -o myfile.o
flags
Or better in Makefile
Files using the routines
Include the header files in quotes, not angle brackets.
Link with .o file produced above.
An example:
Assume code has been decomposed into three files.
A set of files containing sorting routines,
sort.h
and
sort.C
A set of files containing auxiliary routines,
aux.h
and
aux.C
The main program
main.C.
And the
Makefile
In the makefile, you describe this graph