13
votes

I am trying to compile my program with debugging symbols for use in gdb. I have added the -g flag to my makefile but I still get "Reading symbols from ...(no debugging symbols found)" when I load the program in gdb. What is wrong??

Here is a stripped down example of my makefile which should have the relevant bits:

CPP = g++
CFLAGS = -c -g -Wall

$(BIN): $(OBJ)
 $(CPP) $(LDFLAGS) $(OBJ) -o $(BIN) $(LIBS)

<test.o>: <test.cpp>
 $(CPP) $(CFLAGS) <test.cpp> -o <test.o>

If you'd like to see the whole thing you can go here instead, though I don't think it's necessary:

http://pastebin.com/vGNjy0ga

Miscellaneous notes.. I'm compiling with MinGW on Windows and I have SFML and OpenGL as dependencies.

And no, the -s flag is nowhere to be found in my makefile.

6
Can you confirm with make -n that you are indeed getting the -g flag on your compile line?chrisaycock
F:\rowdump\rom\ROMV>make -n g++ -Wall src/obj/core.o src/obj/image.o src/obj/gnd.o src/obj/gat.o src/obj/world.o src/obj/rsw.o src/obj/camera.o src/obj/rsm.o src/obj/main.o -o romv -Wl,--enable-auto-import,-subsystem,windows -lsfml-main -lsfml-graphics -lsfml-window -lsfml-system -lopengl32 -lglu32 It's not there! Weird.. And my -ansi and -pendantic flags are gone too. Edit: Sorry for wall of text. Didn't realize it was gonna turn out like this.delaccount992
the output that Kobie pasted is for default target, which is for linking, and there is no -g flag there. I just confirmed on Ubuntu that that flag is not needed during linking only at compile time. I think you should try "make -n test.o" to see what command is used to compile.binW
As a side note, by convention you use CXXFLAGS for C++ and CFLAGS for plain C.Alexis Wilke

6 Answers

6
votes

Ahh. I'm very sorry. It turns out the "clean:" portion of my makefile is broken. Thus when I used make clean nothing happened. Deleting the .o files manually fixed the problem. The flags work perfectly now. Thanks to everyone who posted anyway! This can be deleted now.

5
votes

I had the same issue when using a makefile I inherited on some old F77 code. I tried all the flags people recommend (-g -ggdb ...etc.) the solution was run make clean If you don't have that or know what it means, basically delete all the compiled (.o) files.

the makefile didn't know to recompile since only flags were changed, so I wasn't actually compiling with -g or -ggdb when I thought it was. Hope this helps someone!

1
votes

try to replace

$(BIN): $(OBJ)
 $(CPP) $(LDFLAGS) $(OBJ) -o $(BIN) $(LIBS)

with

$(BIN): $(OBJ)
 $(CPP) $(CFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS) $(LIBS)

(edit) Note: -c option will not work with executable

1
votes

I dont have much experience with Mingw but try replacing -g with -ggdb. This may solve your problem. According to gcc man page

Produce debugging information for use by GDB. This means to use the most expressive format available (DWARF 2, stabs, or the native format if neither of those are supported), including GDB extensions if at all possible.

1
votes

I think you need -g when linking the object into a binary code.

CPP = g++
CFLAGS = -g -Wall

$(BIN): $(OBJ)
 $(CPP) $(CFLAGS) $(OBJ) -o $(BIN) $(LDFLAGS) $(LIBS)

<test.o>: <test.cpp>
 $(CPP) $(CFLAGS) -c <test.cpp> -o <test.o>
0
votes

I am not sure, but I think you need -g even while linking.