0

制作

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

all: compile run

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

run: One
    ./One

.PHONY: run

我使用 Ubuntu-15.04 作为操作系统,使用 Geany 作为编辑器。

One.c 只包含一个打印语句“hello world”。

4

1 回答 1

1

当您运行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
于 2015-08-24T11:38:54.967 回答