Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 510
delaccount992 Avatar asked Dec 31 '10 06:12

delaccount992


People also ask

What are debugging symbols in GDB?

A Debugging Symbol Table maps instructions in the compiled binary program to their corresponding variable, function, or line in the source code. This mapping could be something like: Program instruction ⇒ item name, item type, original file, line number defined.

How do I add a symbol table in GDB?

To add additional symbols you might use add-symbol-file . The add-symbol-file command reads additional symbol table information from the file filename. You would use this command when filename has been dynamically loaded (by some other means) into the program that is running.

What compiler flag is used to generate a debug build?

The -g flag tells the compiler to generate debugging information.


2 Answers

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.

like image 90
binW Avatar answered Oct 21 '22 13:10

binW


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>
like image 33
ppan Avatar answered Oct 21 '22 14:10

ppan