Combining Several C++ Files (Especially classes) in Unix using Makefile
Written by John Millaway 3-1-2002

 1. NEVER, EVER #include ".cpp" files.

2. Class definitions go in  ".h" files:
   dice_type.h
   counter_type.h

3. Class implementations go in ".cpp" files:
   dice_type.cpp
   counter_type.cpp

4. In main.cpp, #include your ".h" files:
   // main.cpp
   #include "counter.h"
   #include "dice.h"

5. After separately testing each of your program components, such as the counter and dice classes, we can combine these classes and test them together using the Unix Make utility.

Here is a Makefile that will compile everything for you.
We assume that all files required for this project are in the same directory and that nothing else is in that directory.

All you need to do is type "make" and then type the following sequence of lines:

# Save this file as "Makefile".
CC = g++
CXXFLAGS = -Wall -g

# builds a program named "sim"
sim: dice.o counter.o sim.o

# these are generated by:  g++ -MM *.cpp
counter.o: counter.cpp counter.h
dice.o: dice.cpp dice.h counter.h
sim.o: sim.cpp dice.h counter.h

# cleans out your trash
clean:; rm -rf *.o core sim a.out