2014-01-06 63 views
0

我想我已經在makefile中添加了-g選項。生成文件是這樣的:爲什麼在我添加-g參數後沒有加載調試信息

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運行程序:

[email protected]:~/下載/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) 

什麼問題?

回答

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 

那麼你不需要$O: vdefs.hgcc線。您的連接線應該變爲:

${CC} -o [email protected] ${CFLAGS} $O ${LDFLAGS} ${LDLIBS} 

或其附近。

+0

JL沒有想到這一點。 – paxdiablo

相關問題