问题描述
尝试回答停止在 test1.c
的第一个错误,但它开始编译 test2.c
。
我猜这是因为进程启动不同的任务,每个源文件一个,因此选项被应用多次。
问题是:是否有编译器选项工作每gcc命令?
据我所知或可以确定,没有,GCC没有这样的选择。如果它确实有,我希望找到它记录为,或者可能在(其中 -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 gcc stops at the first error of test1.c
but it starts compiling test2.c
.
I guess it is because gcc 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!