美文网首页
make 错误被忽略为哪般?

make 错误被忽略为哪般?

作者: yestyle | 来源:发表于2017-06-10 15:40 被阅读28次

在使用 make 编译时常常出现类似这样的提示:

make[6]: [copyapi] Error 1 (ignored)

找到目标 copyapi 的定义,发现使用了 $(RM) 和 $(CP) 两个变量,而这两个变量定义如下:

RM = -@rm -f
CP = -@cp

rmcp 两个命令前都加了减号(-),表示忽略错误(加 @ 表示不打印命令本身)。

在学习 makefile 时一定学过命令前加减号表示忽略错误,但看到 Error 1 (ignored) 这样的提示时,却没有想到是什么原因导致的,逆向思维有待提高。

看看 GNU make 手册 5.5 Errors in Recipes 对此的描述:

After each shell invocation returns, make looks at its exit status. If the shell completed successfully (the exit status is zero), the next line in the recipe is executed in a new shell; after the last line is finished, the rule is finished.

If there is an error (the exit status is nonzero), make gives up on the current rule, and perhaps on all rules.

Sometimes the failure of a certain recipe line does not indicate a problem. For example, you may use the mkdir command to ensure that a directory exists. If the directory already exists, mkdir will report an error, but you probably want make to continue regardless.

To ignore errors in a recipe line, write a ‘-’ at the beginning of the line’s text (after the initial tab). The ‘-’ is discarded before the line is passed to the shell for execution.

...

When errors are to be ignored, because of either a ‘-’ or the ‘-i’ flag, make treats an error return just like success, except that it prints out a message that tells you the status code the shell exited with, and says that the error has been ignored.

而在调用 make 时传入 -i--ignore-errors 标志将忽略所有的错误,没有前置条件的特殊目标 .IGNORE 也具有同样效果。但使用 '-' 具有更好的扩展性。

上述特性需要与另一标志 -k--keep-going 区别开来。-k 并不会忽略遇到的错误,而是继续其它目标的编译,直到所有目标都执行之后再返回错误。这有助于一次性发现所有错误、做出相应修改并再次编译。这也是 Emacs 的 compile 命令默认使用 -k 标志的原因。

最后需要注意的是,即使编译出现错误,目标文件的时间戳还是会更新。假如源文件没有修改就再次编译,出错的目标文件将不会更新,也就是不会重新编译。此时需要手动删除此目标文件再次编译解决,也可通过增加 .DELETE_ON_ERROR 目标实现自动删除的目的。

关于 @ 符号可参考 5.2 Recipe Echoing 的描述。

以上。

相关文章

  • make 错误被忽略为哪般?

    在使用 make 编译时常常出现类似这样的提示: make[6]: [copyapi] Error 1 (igno...

  • 时被忽略为哪般

    时被忽略为哪般 一盆茂盛的文竹,端来时郁郁葱葱,现在却让我养的好多叶子都枯黄落下来了。其中的原因之一,就是...

  • 2019-06-28扑蝇记

    屋里飞进一只苍蝇,鬼魅一般在屋里盘旋,走哪跟哪,不知哪里的角落它突然就晃悠出来,却偏偏像流萤一般悄无声息忽尔出现忽...

  • windows环境下配置GNU make环境

    在windows环境下使用make命令出现下面的错误 错误原因: 未安装 make for windows; 未...

  • protocol buffers make install安装错

    make install 如果出现如下错误 Making install in .make[2]: Nothing...

  • mk错误总结

    错误: missing and no known rule to make it 错误: LOCAL_SDK_V...

  • 2020-11-27

    忽喜忽悲六月天 时哭时笑孩子脸 人在事中事饶心 迷迷糊糊为哪般

  • 解决在安装libevent时无法找到openssl的问题

    问题描述: 在make的时候提示入下错误 libevent-2.1.8-stable make /Library/...

  • 无端被锁为哪般

    一个多月,有三篇文章被锁。第一次是《等待,归来的忏悔2》,那几天,我每天都会向不同的专题投稿,其用意在于尝试还有没...

  • 文章被锁为哪般?

    写作是一件很辛苦的事,简书是一个为写作者提供文字表现的平台。 陆陆续续已经在简书上发布了二十多篇文...

网友评论

      本文标题:make 错误被忽略为哪般?

      本文链接:https://www.haomeiwen.com/subject/vptcqxtx.html