Multi-file Compilation


Separating interface from implementation

In Java:

 

In C++:

 

Header file contains:

 

 

 

 

Source file contains:

 

 

 

 


Preprocessor

preprocessor command = any line beginning with #

#define

 

 

 

 

 

#include

 

 

 

 

 

conditional compilation

What if, with all your nested #includes, you end up having a definition show up more than once?

 

 

 

 

 

 

 

 


Compiling with multiple files in your project

To compile all at once (only useful if you have just a couple files):

g++ ExampleObj.cpp testExampleObj.cpp -o runIt

OR

Can compile separately, creating object files (ending in .o):

g++ -c ExampleObj.cpp
g++ -c testExampleObj.cpp

and then link:

g++ ExampleObj.o testExampleObj.o -o runIt