简体   繁体   English

如何使用Makefile为C生成调试符号? [Linux的]

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

I'm trying to use GDB and KDEvelop to debug a console app under Knoppix VM. 我正在尝试使用GDB和KDEvelop在Knoppix VM下调试控制台应用程序。 KDevelop and GDB don't break at my breakpoints. KDevelop和GDB不会破坏我的断点。 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. 如果我是正确的,我如何更改我的Makefile来创建它们。 Maybe the problem is somewhere else? 也许问题出在其他地方?

Regards, Ariel 此致,Ariel

Include -g in the flags sent to the compiler and linker. 在发送给编译器和链接器的标志中包含-g The default variables for this are CFLAGS and LDFLAGS respectively. 其默认变量分别为CFLAGSLDFLAGS

The second step: exclude -s from flags ( -s means strip ) 第二步:从标志中排除-s-s表示条带

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. 详细说明您正在做什么以及您看到的消息,我们可以更具体。

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. 此处的CFLAGS适用于编译器和链接器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM