A Makefile
for C++ programs needs some minor modifications.
Unfortunately, for C++ there are few standards: C++ implementation files
can have a .c
, .C
or .cc
extension, and a compiler
can recognize any combination of these extensions as source files.
Different make implementations can have different default macros
for compiler names too.
GNU Make defines CXX
as g++
by default and uses
CXXFLAGS
to pass flags to the C++ compiler.
Solaris Make defines CCC
as CC
by default and uses
CCCFLAGS
to pass flags to the C++ compiler.
We should therefore never rely on default implicit rules provided by a certain
flavor of make.
Always write a %.o: %.C
or %.o: %.cc
pattern rule, depending on
which extension you use for your implementation files.