我想我在makefile中添加了-g
选项。 makefile是这样的:
C=edgelist.c geometry.c heap.c main.c memory.c output.c voronoi.c
O=edgelist.o geometry.o heap.o main.o memory.o output.o voronoi.o
tt: voronoi t
./voronoi -t <t >tt
voronoi: $O
cc -g -o voronoi $O -lm
$O:vdefs.h
voronoi.tar : $C vdefs.h Makefile Doc t
tar -cf voronoi.tar $C vdefs.h Makefile Doc t
mailable: $C vdefs.h Makefile t
bundle $C vdefs.h Makefile t > mailable
当gdb
运行程序时:
jack@ubuntu:~/下载/voronoi$ gdb ./voronoi
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/jack/下载/voronoi/voronoi...(**no debugging symbols found**)...done.
(gdb)
有什么问题?
答案 0 :(得分:2)
每个目标文件都必须使用-g
创建,并且可执行文件必须与-g
链接。目前,您正在使用-g
进行关联,但未使用-g
进行编译。
鉴于makefile的结构,最简单的修复可能是:
$O: vdefs.h
gcc -g -c $*.c
但是,理想情况下,您应该进行设置,以便使用CC和CFLAGS。例如:
CFLAGS = -g -Wall -Wextra -Werror
CC = gcc # May be unnecessary
LDLIBS = -lm
然后,gcc
之后您不需要$O: vdefs.h
行。您的链接行应该成为:
${CC} -o $@ ${CFLAGS} $O ${LDFLAGS} ${LDLIBS}
或左右。