多个文件编译错误时停止GCC [英] Stop GCC on error with multiple files compilation

查看:225
本文介绍了多个文件编译错误时停止GCC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试回答此SO问题我发现了gcc选项




  • -Wfatal-errors

  • -fmax-errors = n



per compilation unit



我的意思是,使用2个源代码c文件并使用命令进行编译

  gcc -Wall -Wextra -pedantic -Wfatal-errors -o test test1.c test2.c 

并将垃圾写入这两个文件中,我看到 gcc 停止在 test1.c 的第一个错误,但它开始编译 test2.c

我猜这是因为 gcc 进程启动不同的任务,每个源文件一个,因此选项被应用多次。



问题是:是否有编译器选项工作每gcc命令?

解决方案

据我所知或可以确定,没有,GCC没有这样的选择。如果它确实有,我希望找到它记录为 Overall Option ,或者可能在请求或禁止警告的选项(其中 -Wfatal-errors 已记录)。两个部分都不会描述此类选项,整个选项摘要列出了任何看起来合适的选项,超出了问题中已讨论和拒绝的选项。



请注意, GCC 6.2.0的文档,是本文写作的最新版本。我认为假定如果问题寻求的选项存在于早期版本中,那么它将被结转,但是我没有执行GCC文档的详尽搜索,这是需要证明这一点是相当安全的。



对我来说最有希望的替代方法是简单地通过单独的 gcc 命令编译每个翻译单元,然后在单独的步骤中将它们链接在一起。 Makefile通常以这种方式工作,并且GNU Make将在没有构建任何目标后停止,前提是它的 -k / - keep -going 选项未启用。


Trying answering to this SO question I found out that gcc options

  • -Wfatal-errors
  • -fmax-errors=n

works "per compilation unit"

I mean, using 2 source code c file and compiling with command

gcc -Wall -Wextra -pedantic -Wfatal-errors -o test test1.c test2.c

and writing garbage into both files I see that stops at the first error of test1.c but it starts compiling test2.c.

I guess it is because process launches different tasks, one for each source file, so options are applied multiple times.

The question is: is there a compiler option that works "per gcc command"?

解决方案

As far as I know or can determine, no, GCC has no such option. If it did have, I would expect to find it documented either as an "Overall Option", or possibly among the "Options to Request or Suppress Warnings" (where -Wfatal-errors is documented). Neither section describes such an option, nor does the overall option summary list anything that seems appropriate, beyond those options already discussed and rejected in the question.

Note that I've referred to and linked the docs for GCC 6.2.0, the most recent version as of this writing. I think it is reasonably safe to assume that if an option such as the question seeks were present in an earlier version then it would have been carried forward, but I have not performed the exhaustive search of GCC documentation that would be required to prove that.

The alternative that seems most promising to me is simply to compile each translation unit via a separate gcc command, and then link them together in a separate step. Makefiles are often structured to work in this way, and GNU Make will stop after failing to build any target, provided that its -k / --keep-going option is not enabled.

这篇关于多个文件编译错误时停止GCC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆