The quick solution
You are not using CFLAGS
in your recipes so it is having no effect.
It should work if you change lines 8 to 15 to:
8 main.o : main.cpp hash.h
9 $(CC) $(CFLAGS) main.cpp
10
11 hash.o : hash.cpp hash.h
12 $(CC) $(CFLAGS) hash.cpp
13
14 hash_function.o : hash_function.cpp hash.h
15 $(CC) $(CFLAGS) hash_function.cpp
Some extra details
-D
is a compile time flag not a link time option.
CFLAGS
is conventionally used to pass compile time flags to the compiler for a C program.
Normally CXXFLAGS
would be used for a C++ program such as this and CXX
to specify the C++ compiler. Make doesn't really mind though but it can make it easier to follow when conventions are used.
LDFLAGS
is normally used for passing link time flags like -lrt
so it only makes sense to use that on line 6, not in the compiling steps.