0

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) ?

Community
  • 1
  • 1
Jay
  • 179
  • 1
  • 5
  • 18
  • Which debug files? – 2501 Sep 19 '16 at 22:37
  • Did you confirm that it is not building the objects with debug symbols? – blackpen Sep 19 '16 at 22:39
  • 2
    "I can't seem to be able to build the debug files ". Why not? Tell us specifically what you observe and how you came to that conclusion. – kaylum Sep 19 '16 at 22:51
  • Side note: your linking rule is broken as it creates `$(BDIR)/$(NAME)`, but you tell make it creates `$(NAME)`. – user657267 Sep 19 '16 at 23:03
  • @kaylum `make` create the `obj/` dir with `.o` files and the `bin/` dir has `MySuperProgram` inside it. What's missing is `bin/MySuperProgram.dSYM` dir with all the debug infos. I came to that conclusion with simple tests with `g++ -g test_main.cpp`. @user657267, how to fix it so that it also creates the debug files ? So far I haven't got much luck with it. I have been at it for couple hours with the gnu make docs. – Jay Sep 20 '16 at 08:22
  • 1
    "What's missing is bin/MySuperProgram.dSYM". What makes you think that g++ will produce that file? That's not how it works. The debugging info is embedded in the object, not a seperate file. If you run `gdb` on `MySuperProgram` then you should be able to see the debugging info. That's the way to test it. – kaylum Sep 20 '16 at 08:30
  • Oh, I was confused with an other project which was build with Xcode, see this post http://stackoverflow.com/questions/17743993/dsym-files-generated-from-command-line-mac. Thank you very much @kaylum. – Jay Sep 20 '16 at 08:42

0 Answers0