No debugging symbols in gdb even when compiling with the -g flag

I am trying to compile my program using debugging symbols for use in gdb. I added the -g flag to my makefile, but I still get "Reading characters from ... (no debug characters found)" when I load the program in gdb. What's wrong?

Here is a stripped down example of my makefile, which should have the corresponding 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 want to see all this, you can go here, although I do not think it is necessary:

http://pastebin.com/vGNjy0ga

Various notes .. I am 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.

+8
c ++ gcc makefile gdb debug-symbols
source share
6 answers

Ahhh. I'm sorry. It turns out part of my make clean file is cleaned up. Thus, when I used make clean, nothing happened. Problem deleting .o files manually. Flags now work fine. Thanks to everyone who posted anyway! Now it can be deleted.

+5
source share

I had the same problem when using a makefile that I inherited from old F77 code. I have tried all the flags that people recommend (-g -ggdb ... etc). the decision was made to clear If you do not know this or know what it means, basically delete all the compiled (.o) files.

makefile did not know to recompile, since only the flags were changed, so I was not going to compile with -g or -ggdb when I thought it was. Hope this helps someone!

+3
source share

try replacing

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

from

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

(edit) Note. The -c option will not work with the executable

+1
source share

I'm not sure, but I think you need -g even when connecting.

0
source share

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

Generate debugging information for use by GDB. This means (DWARF 2, stabs, or native format, if none of them are supported), including GDB extensions, if at all possible.

0
source share

I think you need -g when binding the object to binary.

 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
source share

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


All Articles