make总是重建所有目标

时间:2015-08-24 08:27:49

标签: ubuntu makefile geany ubuntu-15.04

开启

  

重建编译和运行目标,即使对文件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”。

1 个答案:

答案 0 :(得分:1)

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

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

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

all: compile run

compile: One

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

run: One
    ./One

.PHONY: run compile
相关问题