【问题标题】:make always rebuilds all targetsmake 总是重建所有目标
【发布时间】:2015-08-24 08:27:49
【问题描述】:

开启

制作

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

【问题讨论】:

    标签: ubuntu makefile geany ubuntu-15.04


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2014-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-11
      • 2013-09-16
      • 2013-10-05
      • 1970-01-01
      • 2015-09-24
      相关资源
      最近更新 更多