In my Makefile I am using the -DDEBUG Flag for debugging which works fine (compiles and right output) in the following minimal example:
# Makefile
all : debug
CXX = g++
CXXFLAGS = -std=c++11 -Werror -Wall -Wextra -Wno-unused-value
SOURCES = main.cpp vector.cpp
OBJECTS = $(subst .cpp,.o, $(SOURCES))
debug: $(OBJECTS)
$(CXX) $(CXXFLAGS) -DDEBUG -o Program $(OBJECTS)
./Program
clean:
rm *.o Program
.PHONY: clean debug
But when i copy all project-files into the Folder the Debug-Flag wont be set (tested with #ifdef DEBUG and cout). I am adding the following files:
ind.hpp ind.cpp debug.hpp debug.cpp
I first thought debug.* could be the problem, but ".PHONY: clean debug" didn't help.
DEBUG
in that makefile. That isn't working the way you expect. You need that on the compilation line not the linking line. Add it toCXXFLAGS
. – Etan ReisnerNDEBUG
for non-debug forms (and not settingNDEBUG
when debugging!) is followed by assert(3) – Basile StarynkevitchMakefile
, I would suggest you use a tool to generate it. I likecmake
. The old way is theautomake
(which is pretty terrible, if you ask me). There are others too. These would create the correctMakefile
for you. – Alexis Wilke