【发布时间】:2011-01-16 03:14:57
【问题描述】:
#####################################################################
# This is the filesystem makefile "make_BuddyAlloc".
# Author:Michael Gomes
# Date:2 jan 2011
######################################################################
#variable defination
CC = gcc
CFLAGS = -g -O2
SRC_DIR=src
INC_DIR=inc
OBJ_DIR=obj
#List of source files
SOURCE= buddyMain.c \
Copy.c \
#List of object files
OBJECTS=$(addprefix $(OBJ_DIR)/,$(SOURCE:.c=.o))
#BuddyAlloc is dependent on "obj/*.o".
BuddyAlloc : $(OBJECTS)
$(CC) $(CFLAGS) -o BuddyAlloc $<
#obj/*.o depends on src/*.c and inc/*.h, we are redirecting the object files to obj folder
$(OBJECTS):$(SRC_DIR)/$(SOURCE)
$(CC) $(CFLAGS) -I$(INC_DIR) -o $(OBJ_DIR)/$(OBJECTS) -c $<
#Cleans all the *.exe files
clean:
rm -f *.exe
我将源文件保存在 src 文件夹下,包括 inc 文件夹下,目标文件保存在 obj 文件夹中。上面给出的是我试图为我的迷你项目创建的 makefile。 我不断收到错误 no rule to make target 'Copy.c' required by 'obj/buddyAlloc.o',但如果我不包含 Copy.c,它工作正常,我做错了什么?
【问题讨论】:
-
当心尾随反斜杠,如 SOURCE 列表中 Copy.c 之后的反斜杠。在这种情况下,您没问题,但一般情况下,请避免让列表以反斜杠结尾。