make 总是重建所有目标

make always rebuilds all targets

make

编译和 运行 目标都被重建,即使 没有对文件 One.c 进行更改

all: compile run

compile: One.c
    gcc One.c -o One

run: One
    ./One

.PHONY: run

我使用 Ubuntu-15.04 作为 OS,使用 Geany 作为编辑器。

One.c 只包含一个打印语句,"hello world"。

当您 运行 make 时,它将尝试在 makefile (all) 中构建第一条规则,这取决于目标 compilerun

run 是假的,无论如何都会是 运行。 compile 是非伪造的,但没有名为 compile 的文件,因此 make 将尝试构建此目标(期望它生成 compile 文件,但它不会)。

您需要添加 One 非虚假目标并在此处构建您的二进制文件,例如:

all: compile run

compile: One

One: One.c
    gcc One.c -o One

run: One
    ./One

.PHONY: run compile