如果我尝试make all,我得到:

make: ***No rule to make target 'src\SOURCES', needed by 'all'. Stop.

如果我尝试make qwark,我得到:
make: ***No rule to make target 'obj\src\SOURCES' needed by 'qwark'. Stop.

如果我尝试make qwark.o,我得到
Fatal error: can't create obj\qwark.o: No such file or directory
make: *** [qwark.o] Error 1

这是我的源代码,供您欣赏。
COMPILER := g++
CFLAGS :=
LDFLAGS :=
SOURCES := quark.cc
SOURCES := $(addprefix src\,SOURCES)
OBJECTS := $(addprefix obj\,$($(notdir SOURCES):.cc=.o))
EXECUTABLE := qwark.exe
DEBUG := bin\debug\$(EXECUTABLE)
NORMAL := bin\release\$(EXECUTABLE)

all: $(SOURCES) $(EXECUTABLE)

release: qwark
normal: qwark

qwark: $(OBJECTS)
    $(CC) $(LDFLAGS) $(OBJECTS) -o $@

qwark.o: src\qwark.cc
    $(CC) $(CFLAGS) -c src\qwark.cc -o obj\qwark.o

%.o: src\%.cc
    $(CC) $(CFLAGS) -c $(input) -o obj\$(output)

拜托,有人,告诉我我在做什么错..........

最佳答案

您正在修改文字SOURCES字,而不是相应的变量值。请尝试以下操作:

SOURCES := quark.cc

SOURCES := $(addprefix src\,$(SOURCES))
OBJECTS := $(addprefix obj\,$(patsubst %.cc,%.o,$(notdir $(SOURCES))))

或者,简单得多:
SOURCES := quark.cc

OBJECTS := $(SOURCES:%.cc=obj\%.o)
SOURCES := $(SOURCES:%=src\%)

关于makefile - 与makefile有关的噩梦,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9150739/

10-10 20:32