现在我有一个这样的makefile:

#--------------------------------------------------------
#  Choose  a  compiler
#--------------------------------------------------------
CC = gcc

#--------------------------------------------------------
#  Set  your  source  file  and  your  target  executable
#--------------------------------------------------------
SRC = main.c
TARGET = main2

all: $(TARGET)

#--------------------------------------------------------
#  Compile  the  program
#--------------------------------------------------------
$(TARGET): $(SRC)
    $(CC)  -o  $@  $(SRC)

#--------------------------------------------------------
#  Clean  up  (remove  the  executable)
#--------------------------------------------------------
clean:
    rm  -f  $(TARGET)

如何修改我的Makefile以便它自动编译-g和-O0(这是oh zero)选项?我真的对makefile的东西很困惑。

最佳答案

在cc下加上
改变路线
CFLAGS=-g -O0
进入之内
$(CC) -o @ (SRC)
这将生成一个最终的Makefile,它看起来像:

CC = gcc
CFLAGS = -g -O0

SRC = main.c
TARGET = main2

all: $(TARGET)

$(TARGET): $(SRC)
    $(CC) -o $@ $(CFLAGS) $(SRC)

clean:
    rm  -f  $(TARGET)

07-24 09:45
查看更多