How to generate Debug symbols with Makefile for C? [Linux]

假装没事ソ 提交于 2019-12-03 17:24:58

问题


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


回答1:


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)




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1937420/how-to-generate-debug-symbols-with-makefile-for-c-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!