Project structure:
- Makefile
- /src
- /include
I have the following Makefile for a C++ project. It builds fine but I can't seem to be able to build the debug files with the -g flag.
Here's the Makefile:
NAME := MySuperProgram
BDIR := bin
ODIR := obj
SRC := $(wildcard src/*.cpp)
OBJ := $(SRC:src/%.cpp=$(ODIR)/%.o)
CXXFLAGS := -W -Wall -Werror
.PHONY: all debug clean fclean re
all: $(NAME)
debug: CXXFLAGS += -DDEBUG -g
debug:all
$(NAME): $(OBJ) | $(BDIR)
$(CXX) $(CXXFLAGS) $^ -o $(BDIR)/$@
$(ODIR)/%.o: src/%.cpp | $(ODIR)
$(CXX) $(CXXFLAGS) -c -o $@ $<
$(ODIR) $(BDIR):
@mkdir -p $@
clean:
$(RM) -r $(ODIR)
fclean: clean
$(RM) -r $(BDIR)
re: fclean all
Environment:
Debian 8
GCC 4.9.2
I have read How can I configure my makefile for debug and release builds? but it's not helping on this particular case.
How to make it build with debug symbols in the $(BDIR) ?