C语言中的Makefile问题

时间:2015-11-28 14:44:00

标签: c gcc makefile

12.15 am --> 12.15, 1.30 am --> 1.30, 12.15 pm --> 24.15 pm, 1.15 pm --> 13.15

我在include文件夹中包含了所有“标题”文件。我的所有源代码都在src文件夹中(Lab12.c,Function1.c,Function2.c ...)。当我使用make命令时,我不断收到此错误。

Makefile:45:target #----------------------------------------------------------------------- ------ # 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 #-------------------------------------------------------------------- Function2.c'与目标模式不匹配 Makefile:45:target Function1.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代码文件夹中,为什么系统不识别它们?

1 个答案:

答案 0 :(得分:4)

SRCS=$(SRCDIR)/Lab12.c \ Function1.c \ Function2.c \ Function3.c \

似乎错了;你应该试试

SRCS=$(SRCDIR)/Lab12.c Function1.c Function2.c Function3.c

代替

<强>更新

如果Function1.c等在'$(SRCDIR)`中,则必须将目录添加到这些文件中。 (来自M Oehm的评论)