How to generate Debug symbols with Makefile for C?

2020-06-03 04:23发布

I'm trying to use GDB and KDEvelop to debug a console app under Knoppix VM. KDevelop and GDB don't break at my breakpoints. I suspect it's because they don't have debug symbols.

If I'm correct how do I need to change my Makefile to create those. Maybe the problem is somewhere else?

Regards, Ariel

3条回答
我只想做你的唯一
2楼-- · 2020-06-03 04:35

Include -g in the flags sent to the compiler and linker. The default variables for this are CFLAGS and LDFLAGS respectively.

The second step: exclude -s from flags (-s means strip)

查看更多
我欲成王,谁敢阻挡
3楼-- · 2020-06-03 04:48

If you are able to see source and set the breakpoint, then you probably have debugging symbols established. However, the usual sequence is:

gcc -g -o (outputname) (source files...)
gdb outputname

Give more specifics about what you are doing and what messages you see and we can be more specific.

查看更多
淡お忘
4楼-- · 2020-06-03 04:51

The full example would be:

CFLAGS =-g

all: program.o
    gcc -o program program.o

The CFLAGS here is applied to both the compiler and the linker.

查看更多
登录 后发表回答