Reputation: 59
I cannot determine the reason that gdb is either not finding the proper debugging symbols or they are not being generated by my makefile. I have added and removed various flags such as -g, -ggdb, and -O0 in as many combinations as I can think of. Any help would be appreciated!
Makefile:
FLAGS =-std=c++11 -ggdb -g -O0 -Wall -Werror
CC = g++
OBJS = main.o LSorter.o LNode.o
default: exec
exec: $(OBJS)
$(CC) $(FLAGS) -o exec $(OBJS)
main: main.cpp LSorter.h LNode.h
$(CC) $(FLAGS) -c main.cpp -o main.o
LSorter: LSorter.cpp LSorter.h LNode.h
$(CC) $(FLAGS) -c LSorter.cpp -o LSorter.o
LNode: LNode.cpp LNode.h
$(CC) $(FLAGS) -c LNode.cpp -o LNode.o
clean:
rm exec $(OBJS)
Console Output:
Upvotes: 1
Views: 242
Reputation: 118425
OBJS = main.o LSorter.o LNode.o
exec: $(OBJS)
$(CC) $(FLAGS) -o exec $(OBJS)
This specifies that the exec
target depends on main.o
, LSorter.o
, and LNode.o
targets.
The make
command then proceeds to search your Makefile for any rules to build main.o
, Lsorter.o
, and LNode.o
.
Unfortunately, make
fails miserably in this noble quest. Your Makefile
fails to define any rules for targets named main.o
, Lsorter.o
, and LNode.o
. make
then defaults to using its implicit rules, that build .o
files from .cpp
files that it finds with the same name. The default built-in rules, that are built into make
, know absolutely nothing about your FLAGS
variables, and if you paid close attention to the commands that make
was executing when compiling your cpp
file you would've noticed that your cpp
files were not compiled with your FLAGS
, and therefore did not have any debugging data compiled in.
Your makefile does appear to have rules defined for targets main
, LSorter
and LNode
, which use FLAGS
to specify the -g
option.
Unfortunately, those are not the targets that make
was instructed to search for, as I explained.
This is an obvious oversight. Change your build rules to specify the correct dependency targets, then make clean
and recompile.
Upvotes: 1