C++ 如何指示 GCC 在 5 个错误后停止?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3223732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to instruct GCC to stop after 5 errors?
提问by yegor256
Is it possible to instruct GNU c++ compiler to stop after 5 errors found? Can't find this in documentation.
是否可以指示 GNU c++ 编译器在发现 5 个错误后停止?在文档中找不到这个。
回答by zwol
The command-line option -fmax-errors=N
directs the compiler to give up after Nerrors. This option is present in GCC 4.6 and later.
命令行选项指示编译器在出现N 个错误后放弃。此选项存在于 GCC 4.6 及更高版本中。-fmax-errors=N
The command-line option -Wfatal-errors
directs the compiler to give up after oneerror. This option is present in GCC 4.0 and later.
命令行选项-Wfatal-errors
指示编译器在一次错误后放弃。此选项存在于 GCC 4.0 及更高版本中。
In both cases, warnings do not count toward the limit unless you also specify -Werror
.
在这两种情况下,警告不计入限制,除非您还指定了-Werror
。
回答by user1993934
You can use gcc option:
您可以使用 gcc 选项:
-fmax-errors=5
for this purpose.
以此目的。
回答by Tomasz Romanowski
I would welcome such an option as well. For now, I'm using the following workaround to get the first five errors:
我也欢迎这样的选择。现在,我正在使用以下解决方法来获取前五个错误:
<make> 2>&1|grep error|head -5
回答by wheaties
I have to ask why you would want to do this. Sometimes the error that exists in the code is not the first or even found in the first five errors. Sometimes it's beyond that and only is recognizable once you scroll down the list. A better method might be to break up your code and place it into smaller libraries if you're bothered by compile times. Or if you're concerned with things scrolling off the screen of a command line, using the '>>' operator to pipe the messages into a file.
我不得不问你为什么要这样做。有时代码中存在的错误不是第一个,甚至不是在前五个错误中发现的。有时它超出了这个范围,只有向下滚动列表才能识别。如果您对编译时间感到困扰,一个更好的方法可能是分解您的代码并将其放入较小的库中。或者,如果您担心从命令行屏幕滚动出来的内容,请使用“>>”运算符将消息通过管道传输到文件中。