有makefile相关的噩梦

时间:2012-02-05 16:14:24

标签: makefile

如果我尝试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)

请有人告诉我这是错的..........

2 个答案:

答案 0 :(得分:4)

您正在修改文字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\%)

答案 1 :(得分:2)

在rhs上展开SOURCES变量?

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