How to debug a project using makefile

I am new to both makefiles and projects using multiple files. Now I have one main.c and two user libraries. Here's the makefile:

CC = gcc
OBJECTS = main.o path.o util.o

9_1 : $(OBJECTS)
    $(CC) -g $(OBJECTS) -o 9_1

main.o : main.c path.h util.h
    $(CC) -g -c main.c path.h util.h
path.o : path.c path.h util.h
    $(CC) -g -c path.c path.h util.h
util.o : util.c util.h
    $(CC) -g -c util.c util.h

.PHONY : clean
clean : 
    rm $(OBJECTS)

I would like to be able to debug this project in Emacs (using a multiple window variable), however, when I run gdb -i=mi 9_1(the default parameter) and try to add breakpoints in main.c, it does not allow me. In particular: I run b main.c:25and I get

No symbol table is loaded. Use the "file" command.
Breakpoint 1 (main.c:25) pending

What should I do?

+4
source share
1 answer

This happened because

  • you have already created your objects / executables without a flag -g
  • after that you added a flag -g

make . clean,

make clean
make

-g: . .

: gcc. , make ( ), .c. .o.

+3

Source: https://habr.com/ru/post/1690433/


All Articles