我已将-g选项添加到makefile中,如下所示:
CFLAGS=-Wall -g
all:
cc hello.c -o hello
cc badprog.c -o badprog
当我使用make:
进行编译时 cc hello.c -o hello
cc badprog.c -o badprog
我在这里看不到-g
选项。valgrind --track-origins=yes ./badprog
的结果如下:
==14412== Conditional jump or move depends on uninitialised value(s)
==14412== at 0x4E7D665: _itoa_word (_itoa.c:179)
==14412== by 0x4E81B91: vfprintf (vfprintf.c:1654)
==14412== by 0x4E880A8: printf (printf.c:34)
==14412== by 0x400564: main (in /home/anr/Desktop/c programming/badprog)
==14412== Uninitialised value was created by a stack allocation
==14412== at 0x40052C: main (in /home/anr/Desktop/c programming/badprog)
答案 0 :(得分:3)
因为编译命令中未引用CFLAGS
。将Makefile修改为:
CFLAGS=-Wall -g
all:
cc hello.c $(CFLAGS) -o hello
cc badprog.c $(CFLAGS) -o badprog