有没有办法在命令行获得可读的 gcc 错误和警告输出?

发布于 2024-07-15 01:16:43 字数 154 浏览 6 评论 0原文

对于一些长错误,gcc 输出很密集,并且有很多换行等。特别是当错误很细微时,我可能需要眯着眼睛 10-30 秒才能用眼睛解析它。

我已将其粘贴到打开的代码编辑器窗口中,以获得一些基本语法突出显示并启用正则表达式的重新格式化。

有人发明了更自动化的方法吗?

For some long errors, the gcc output is dense and has lots of line-wrapping etc. Especially when errors are subtle, it can take me 10-30 seconds of squinting to parse it with my eyes.

I've taken to pasting this in an open code-editor window to get some basic syntax highlighting and enable reformatting with regex's.

Has anyone invented a more automated method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

围归者 2024-07-22 01:16:44

我发现 colorgcc 非常宝贵。 通过引入着色,在心理上解析 gcc 错误消息的文本变得更加容易,尤其是在涉及模板时。

I've found colorgcc to be invaluable. By introducing coloring, it becomes much easier to mentally parse the text of gcc error messages, especially when templates are involved.

那支青花 2024-07-22 01:16:44

如果您的错误与模板相关,请查看 STLfilt:

If your errors are template related, take a look at STLfilt:

抽个烟儿 2024-07-22 01:16:44

gccfilter 进行着色和处理 消息的简化。

http://www.mixtion.org/gccfilter/

gccfilter does coloring & simplification of messages.

http://www.mixtion.org/gccfilter/

强者自强 2024-07-22 01:16:44

如果您使用 GCC 4.9,则可以添加 -fdiagnostics-color=auto 作为附加编译标志。 在某些更高版本中,该颜色已默认启用。

If you use GCC 4.9, you can add -fdiagnostics-color=auto as an additonal compilation flag. At some later version, the color has been enabled by default.

冷月断魂刀 2024-07-22 01:16:44

检查 diagcc ,你可以得到这样的东西:

colored message demo

如果您的 gcc ≥ 4.9,您可以使用参数 -fdiagnostics-color=always

check diagcc out, you can get something like this:

colored message demo

If your gcc ≥ 4.9, you can use argument -fdiagnostics-color=always.

静谧幽蓝 2024-07-22 01:16:44

4年后回答你的问题,这里应该提到clang

To answer your question 4 years later, clang should be mentioned here.

花开半夏魅人心 2024-07-22 01:16:44

这是我当前的 hack,主要是在战略位置插入换行符和缩进以及一些额外的注释,但对解决 STL 的冗长问题没有任何作用。

请注意,按照当前实现的情况,如果编译器返回错误,此脚本不会返回错误,因此执行类似的操作将无法正常工作: (make && ./runApplication)< /代码>。 这肯定可以由具有更好 bash-fu 的人来解决。

#!/bin/bash
# SUBSTITUTION RULES:
# Note: All substitution rules must end in a semi-colon, inside of the closing quote
subColonSpace='s/: /:\n /g;'
subSrc='s/^src/\nsrc/;'
subError='s/error:/error:\n\n======================================\nERROR:/;'
subWarning='s/ *error: *\n/ERROR: /;'
subWarning='s/ *warning: *\n/WARNING: /;'
subNote='s/note:/\n NOTE:/g;'
subOpenTic='s/‘/\n   ‘/g;'
subOpenParen='s/(/(\n      /g; s/(\n *)/()/g;'
subCommaSpace='s/, /,\n      /g;'

# Note: The order of these may matter
sedExpr="$subColonSpace $subSrc $subError $subWarning $subNote $subOpenTic      
$subOpenParen $subCommaSpace"

makelogFile=makelog.tmp

make "$@" 2>&1 | sed "$sedExpr" | tee $makelogFile

Here's my current hack, which mostly inserts newlines and indentation in strategic locations along with a little extra annotation, but does nothing to address STL verbosity.

Note that as currently implemented, this script does not return an error if the compiler returned one, so doing something like this will not work properly: (make && ./runApplication). This could surely be remedied by someone with better bash-fu.

#!/bin/bash
# SUBSTITUTION RULES:
# Note: All substitution rules must end in a semi-colon, inside of the closing quote
subColonSpace='s/: /:\n /g;'
subSrc='s/^src/\nsrc/;'
subError='s/error:/error:\n\n======================================\nERROR:/;'
subWarning='s/ *error: *\n/ERROR: /;'
subWarning='s/ *warning: *\n/WARNING: /;'
subNote='s/note:/\n NOTE:/g;'
subOpenTic='s/‘/\n   ‘/g;'
subOpenParen='s/(/(\n      /g; s/(\n *)/()/g;'
subCommaSpace='s/, /,\n      /g;'

# Note: The order of these may matter
sedExpr="$subColonSpace $subSrc $subError $subWarning $subNote $subOpenTic      
$subOpenParen $subCommaSpace"

makelogFile=makelog.tmp

make "$@" 2>&1 | sed "$sedExpr" | tee $makelogFile
私野 2024-07-22 01:16:44

如果您喜欢 Ruby,那么GilCC! GilCC 非常容易安装(只需将其复制到 bin 文件夹)并且易于使用(只需键入 GilCC 而不是“gcc”或“make”)并且它可以与 GCC 版本一起使用。 与基于 Perl 的脚本不同,GilCC 具有统计信息,例如警告和错误的数量以及编译时间。 您不必弄乱 .bash 文件,而且只要您可以在计算机上运行 Ruby,它就是跨平台的。 因为它具有Ruby的力量; 您可以让 GilCC 做不同的事情,例如触发测试自动化、单元测试或在成功构建后对外部硬件进行编程。

以下是下载页面的链接:http://www.onlysolutionssoftware.com/gilcc/

if you like Ruby there is GilCC! GilCC is very easy to install (just copy it to the bin folder) and easy to use (just type GilCC instead of "gcc" or "make") and it works with GCC version. Unlike Perl based scripts GilCC has statistics such as # of warnings and error and compile time. You don't have to mess with .bash files and it is cross platform as long as you can run Ruby on your machine. Since it has the power of Ruby; you can make GilCC do different things such as trigger test automation, unit test or program external hardware after a successful build.

Here is the link to the download page: http://www.onlysolutionssoftware.com/gilcc/

清君侧 2024-07-22 01:16:43

我使用这个名为 colorize 的脚本:

#!/bin/bash
while read x ; do echo $x ; done \
| sed -e "s/.*error:.*/\x1b[1;36m&\x1b[0m/" \
-e "s/.*warning:.*/\x1b[1;36m&\x1b[0m/" \
-e "s/^\(.*\)\(required from\)/\x1b[1;36m\1\x1b[0mnote: \2/" \
-e "s/^\(.*\)\(In instantiation of\)/\x1b[1;36m\1\x1b[0mnote: \2/" \
-e "s/^\(.*\)\(In member\)/\x1b[1;36m\1\x1b[0mnote: \2/" \
| sed -e "s/error:/\x1b[1;31m&\x1b[1;36m/" \
-e "s/warning:/\x1b[1;35m&\x1b[1;36m/" \
-e "s/note:/\x1b[1;30m&\x1b[0m/"

然后我就这样调用它(使用 make 或任何构建系统):

make |& colorize

​​ 我得到类似于 clang 的颜色输出。

I use this script, called colorize:

#!/bin/bash
while read x ; do echo $x ; done \
| sed -e "s/.*error:.*/\x1b[1;36m&\x1b[0m/" \
-e "s/.*warning:.*/\x1b[1;36m&\x1b[0m/" \
-e "s/^\(.*\)\(required from\)/\x1b[1;36m\1\x1b[0mnote: \2/" \
-e "s/^\(.*\)\(In instantiation of\)/\x1b[1;36m\1\x1b[0mnote: \2/" \
-e "s/^\(.*\)\(In member\)/\x1b[1;36m\1\x1b[0mnote: \2/" \
| sed -e "s/error:/\x1b[1;31m&\x1b[1;36m/" \
-e "s/warning:/\x1b[1;35m&\x1b[1;36m/" \
-e "s/note:/\x1b[1;30m&\x1b[0m/"

Then I just call it like this(using make or whatever build system):

make |& colorize

And I get color output similar to clang.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文