14

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.

delaccount992
  • 1,303
  • 3
  • 15
  • 21
  • 5
    Can you confirm with `make -n` that you are indeed getting the `-g` flag on your compile line? – chrisaycock Dec 31 '10 at 06:22
  • 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 Dec 31 '10 at 06:27
  • 3
    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 Dec 31 '10 at 06:36
  • As a side note, by convention you use `CXXFLAGS` for C++ and `CFLAGS` for plain C. – Alexis Wilke Sep 16 '18 at 23:21

6 Answers6

6

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.

delaccount992
  • 1,303
  • 3
  • 15
  • 21
  • And oddly even though make -n shows that my -g flag has been stripped, in actuality it has not. – delaccount992 Dec 31 '10 at 06:37
  • 2
    binW has a comment above that your `make -n` is only showing the linking portion, not the compiling portion. Make sure you are looking at `make -n test.o` only. – chrisaycock Dec 31 '10 at 06:44
5

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!

Peter Mitrano
  • 2,132
  • 28
  • 31
1

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

Alam
  • 1,536
  • 15
  • 26
  • That's not going to work, because the final executable can't use `-c`. Also, it seems (from a quick test on g++ 4.4.1 on GNU/Linux) that you don't need `-g` when linking. – Matthew Flaschen Dec 31 '10 at 06:23
  • My bad, Yes you are right -c options will not work with executable – Alam Dec 31 '10 at 06:26
1

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.

binW
  • 13,220
  • 11
  • 56
  • 69
1

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>
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
ppan
  • 81
  • 3
0

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