Maybe you should change the INCDIR
to an absolute path rather than a relative one? The current working directory may not be what you think it is while make is running.
There's obviously a problem somewhere because your CFLAGS definitions are not being passed to g++.
Change:
CPP_OBJS = $(TEMP)partyhack.o
to:
CPP_OBJS = $(TEMP)/partyhack.o
Other than that I don't see anything wrong.
Make appears to be using a built-in rule as opposed to your custom rule for *.cpp files. (See the ordering of the -c
and -o
options in make's output -- it's not the same as the ones you wrote). Check the definition of your C++ file rule.
My best guess is that the references to $(TEMP) are throwing it off. Where is this defined?
Also note that for C++, usually the variables CXX
and CXXFLAGS
are used for the compiler program and the flags, respectively. CPP
is used for the C preprocessor program, CPPFLAGS
for preprocessor flags and CFLAGS
is used for the C compiler flags. That's probably why make
is not using your CFLAGS
when using its built-in C++ rules.
What happens here, is that
1) make evaluates the target all
, which resolves to partyhack
.
2) make evaluates the target partyhack
, which resolves to $(CPP_OBJS)
3) make evaluates the target $(CPP_OBJS)
, which resolves to $(TMP)partyhack.o
4) make evaluates the target $(TMP)partyhack.o
which resolves to partyhack.o
This is because TMP is not defined. Also note that the slash is missing after $(TMP)
.
5) make evaluates the target partyhack.o
, and applies the implicit rule g++ -c -o partyhack.o partyhack.cpp
It does not apply the rule you specified, namely $(TEMP)/%.o : $(SRCDIR)/%.cpp
because TEMP is not defined, so this evaluates to /partyhack.o : ./partyhack.cpp
, and we are not building /partyhack.o
because we are not in the root directory.
6) g++ does not find the include file, because the include directories were not passed to it, because your rule was not applied.
To fix this:
First, you need to define TEMP (see Nick Meyers answer).
TEMP = .
Second, you need to change the definition of CPP_OBJS (as Paul R suggested).
CPP_OBJS = %(TEMP)/partyhack.o
This will work if you invoke make inside the directory CppPartyHack/PartyHack.