简体   繁体   English

gcc-Makefile:添加依赖性规则后,目标“全部”的配方失败

[英]gcc - Makefile: recipe for target 'all' failed after adding dependency rule

I have a Makefile that fails every time I run it. 我有一个Makefile,每次运行它都会失败。 I have been altering a Makefile that is compiling a bunch of files into a directory that needs to be made if it is not already. 我一直在修改一个Makefile,该文件将一堆文件编译到一个尚未创建的目录中。 all: fails, and I honestly have no clue why it does. all:失败,老实说,我不知道为什么会这样。

Here is what my Makefile looks like: 这是我的Makefile的样子:

CC=gcc
SRCDIR=src
INCDIR=include
BINDIR=../bin
CFLAGS = -flags
LIBS = -llibrary1 -llibrary2

all: 
    $(BINDIR) \
    $(BINDIR)/program1 \
    $(BINDIR)/program2 \
    $(BINDIR)/program3

$(BINDIR)/program1: $(SRCDIR)/program1.c | $(BINDIR)
    $(CC) $(CFLAGS) $< -o $@ $(LIBS)

$(BINDIR)/program2: $(SRCDIR)/program2.c | $(BINDIR)
    $(CC) $(CFLAGS) $< -o $@ $(LIBS)

$(BINDIR)/program3: $(SRCDIR)/program3.c | $(BINDIR)
    $(CC) $(CFLAGS) $< -o $@ $(LIBS)

$(BINDIR):
    mkdir -p $@

clean:
    rm -f $(BINDIR)/*

I know that the issue has to do with the $(BINDIR) , but I can't figure out what to do. 我知道问题与$(BINDIR) ,但我不知道该怎么办。 The last question I asked on StackOverflow gave me some resources (such as GNU's documentation here ). 最后一个问题,我问StackOverflow上给了我一些资源(如GNU的文档在这里 )。 From my understanding, $(BINDIR) should be made first when I run make, and then the other rules should execute without any issues. 根据我的理解, $(BINDIR)应该在运行make时首先生成,然后其他规则应该没有任何问题地执行。

Here is the error I receive, which I know means that $(BINDIR) is not being created before the rest of the rules execute. 这是我收到的错误,我知道这意味着在其余规则执行之前未创建$(BINDIR)

user@user-Notebook:~/project/folder$ make
../bin \
    ../bin/program1 \
    ../bin/program2 \
    ../bin/program3
make: ../bin: Command not found
Makefile:16: recipe for target 'all' failed
make: *** [all] Error 127

What am I missing? 我想念什么?

Posting this as an answer as it wouldn't fit in a comment: 将其发布为答案,因为它不适合评论:

Would make more sense that $(BINDIR) ( /program ), to be dependent(s) for the all target, not commands: $(BINDIR)/ program )作为所有目标而不是命令的依存关系会更有意义:

all: $(BINDIR) $(BINDIR)/program1 $(BINDIR)/program2 $(BINDIR)/program3

Check [GNU]: An Introduction to Makefiles for more details. 有关更多详细信息,请参见[GNU]:Makefile简介

Things could be taken even further (eg writing an pattern rule that would handle all the files), in order to make the Makefile more compact. 为了使Makefile更加紧凑,可以采取更多措施(例如编写处理所有文件的模式规则 )。

@EDIT0 : @ EDIT0

Per @o11c's comment, I removed some part of the answer that was incorrect 根据@ o11c的评论,我删除了部分错误的答案

As currently written your 'all' rule has no dependencies and a non empty recipe. 如当前所写,您的“全部”规则没有依赖项,并且配方也不为空。 Thus make is trying to execute your dependency list as shell instructions. 因此make正在尝试将您的依赖项列表作为shell指令执行。 This is why you see the command not found error, it is from the shell. 这就是为什么您看到命令未找到错误的原因,它来自外壳程序。 Remove the newline after all: and it should work. 完全删除换行符all:它应该起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM