【发布时间】:2015-11-28 14:44:00
【问题描述】:
#----------------------------------------------------------------------- ------
# Choose a compiler & its options
#--------------------------------------------------------------------------
CC = gcc
OPTS = -W -O3
#--------------------------------------------------------------------------
# Add the debug flag to compile for use by a debugger
#--------------------------------------------------------------------------
#DEBUG=-g
#--------------------------------------------------------------------------
# Add the names of the directories
#--------------------------------------------------------------------------
SRCDIR= src
OBJDIR= obj
INCDIR= include
BINDIR= bin
#--------------------------------------------------------------------
# Add the rest of the source files. Don't forget to add the '\' character
# to continue the line. You don't need it after the last source file
#--------------------------------------------------------------------
SRCS=$(SRCDIR)/Lab12.c \ Function1.c \ Function2.c \ Function3.c \ Function4.c \ Function5.c
#--------------------------------------------------------------------
# You don't need to edit the next few lines. They define other flags
# used in the compilation of the source code
#--------------------------------------------------------------------
INCLUDE = $(addprefix -I,$(INCDIR))
OBJS=${SRCS:$(SRCDIR)/%.c=$(OBJDIR)/%.o}
CFLAGS = $(OPTS) $(INCLUDE) $(DEBUG)
#--------------------------------------------------------------------
# Add the name of the executable after the $(BINDIR)/
#--------------------------------------------------------------------
TARGET = $(BINDIR)/ Lab12
all: $(TARGET)
$(TARGET): $(OBJS)
${CC} ${CFLAGS} -o $@ $(OBJS)
$(OBJS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f $(OBJS)
cleanall:
rm -f $(OBJS)
rm -f Lab12
#--------------------------------------------------------------------
# Add a target named cleanall that will remove the object files as well
# as the executable
#--------------------------------------------------------------------
我的所有“头”文件都在包含文件夹中。我的所有源代码都在 src 文件夹中(Lab12.c、Function1.c、Function2.c ...)。当我使用 make 命令时,我不断收到此错误。
Makefile:45: 目标 Function1.c' doesn't match the target pattern
Makefile:45: target Function2.c' 与目标模式不匹配
Makefile:45: 目标Function3.c' doesn't match the target pattern
Makefile:45: target Function4.c' 与目标模式不匹配
Makefile:45: 目标`Function5.c' 与目标模式不匹配
gcc -W -O3 -Iinclude -c -o Function1.c
gcc:没有输入文件
make: *** [Function1.c] 错误 1
我不明白为什么它会这样。所有这些文件都在 src 代码文件夹中,为什么系统无法识别它们?
【问题讨论】:
-
我的帖子中的格式似乎有问题。在原始 Makefile 中。 Function4.c 和 Function5.c 存在。
-
为了将行粘贴在一起,反斜杠必须是一行的最后一个字符;反斜杠和行尾之间不能有任何其他字符,甚至不能有空格。您可以将各种对象放在一行中,但不必用反斜杠分隔它们。
-
如果
Function1.c等在$(SRCDIR)中,您也必须将目录添加到这些文件中。 (或者您不使用任何文件指定$(SRCDIR)并稍后进行模式替换。)