使忽略错误:-i和-k有什么区别

时间:2018-12-21 20:57:24

标签: makefile

即使依赖项的构建失败,我也希望make继续。我通常使用-i完成此操作。我的一位同事说他使用-k。确实,这个堆栈溢出问题对每个问题都有一个答案:

Make: how to continue after a command fails?

这两个选项之间有区别吗?

这是make手册页针对这两个选项的说明:

   -i, --ignore-errors
        Ignore all errors in commands executed to remake files.

   -k, --keep-going
        Continue as much as possible after an error.  While the 
        target that failed, and those that depend on it, cannot be 
        remade, the  other  dependencies of these targets can be 
        processed all the same.

-k描述的是我认为-i所做的。我确定我缺少了一些东西:有人可以帮助我了解其中的区别吗?

1 个答案:

答案 0 :(得分:3)

考虑此makefile:

all: fail success

all success:
        @echo $@

fail:
        exit 1
        @echo $@

现在运行两个标志:

$ make -i
exit 1
make: [Makefile:7: fail] Error 1 (ignored)
fail
success
all

此标志使make假装特定的配方命令成功,即使它失败了。因此all目标仍在运行,因为make认为fail目标实际上已成功。等效于在每个配方行的开头添加一个-

相对于:

$ make -k
exit 1
make: *** [Makek:7: fail] Error 1
success
make: Target 'all' not remade because of errors.

在这里,知道没有建立fail目标。 success由于-k而运行:它不依赖于fail。但是,all之所以没有构建是因为它确实依赖于fail

我从不需要-i。对我来说似乎很危险。

另一方面,我几乎默认使用-k

相关问题