在Makefile中使用-g为GDB编译

时间:2015-08-04 19:38:39

标签: c makefile

使用Makefiles的新手,并想知道我将如何包含-g命令(以及我需要的任何其他内容)以便编译我的程序以使用gdb运行。这是我给出的Makefile。提前谢谢。

  include parallelDefs

COMMON = dataGen.h utils.h IO.h parseCommandLine.h graph.h graphIO.h graphUtils.h parallel.h sequence.h blockRadixSort.h deterministicHash.h transpose.h
GENERATORS = rMatGraph gridGraph powerGraph randLocalGraph addWeights randDoubleVector fromAdjIdx adjToEdgeArray adjElimSelfEdges

.PHONY: all clean
all: $(GENERATORS)

$(COMMON) :
    ln -s ../../common/$@ .

%.o : %.C $(COMMON)
    $(PCC) $(PCFLAGS) -c $< -o $@

rMatGraph : rMatGraph.o 
    $(PCC) $(PLFLAGS) -o $@ rMatGraph.o 

gridGraph : gridGraph.o 
    $(PCC) $(PLFLAGS) -o $@ gridGraph.o 

powerGraph : powerGraph.o 
    $(PCC) $(PLFLAGS) -o $@ powerGraph.o 

randLocalGraph : randLocalGraph.o 
    $(PCC) $(PLFLAGS) -o $@ randLocalGraph.o 

addWeights : addWeights.o 
    $(PCC) $(PLFLAGS) -o $@ addWeights.o

fromAdjIdx : fromAdjIdx.o 
    $(PCC) $(PLFLAGS) -o $@ fromAdjIdx.o

randDoubleVector : randDoubleVector.o
    $(PCC) $(PLFLAGS) -o $@ randDoubleVector.o

adjToEdgeArray : adjToEdgeArray.C $(COMMON)
    $(PCC) $(PCFLAGS) $(PLFLAGS) -o $@ adjToEdgeArray.C

adjElimSelfEdges : adjElimSelfEdges.C $(COMMON)
    $(PCC) $(PCFLAGS) $(PLFLAGS) -o $@ adjElimSelfEdges.C

clean :
    rm -f *.o $(GENERATORS)
    make clean -s -C data

cleansrc : 
    make -s clean
    rm -f $(COMMON) 

1 个答案:

答案 0 :(得分:1)

如果只使用randLocalGraph选项编译-g,则需要一个明确的规则:

randLocalGraph.o: randLocalGraph.C $(COMMON)
        $(PCC) $(PCFLAGS) -g -c randLocalGraph.C -o $@

将使用隐式规则创建所有其他对象。