【问题标题】:issues with Makefile in CC中的Makefile问题
【发布时间】: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) 并稍后进行模式替换。)

标签: c gcc makefile


【解决方案1】:
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 的评论)

【讨论】:

  • 或者将它们放在不同的行上,每行 - 除了最后一个 - 以反斜杠结尾
  • 我根据这篇文章中的建议更改了行。但是,我仍然收到错误消息。预先添加目录到底是什么意思?
  • SRCS=$(SRCDIR)/Lab12.c $(SRCDIR)/Function1.c $(SRCDIR)/Function2.c $(SRCDIR)/Function3.c
  • @JohnDoe :如果它回答了您的问题,请接受答案。您可以通过单击 OznOg 答案旁边的复选标记来接受答案。谢谢,欢迎使用 StackOverflow!
猜你喜欢
  • 2020-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-06
  • 1970-01-01
相关资源
最近更新 更多