有没有办法在命令行获得可读的 gcc 错误和警告输出?
对于一些长错误,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
我发现 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.
如果您的错误与模板相关,请查看 STLfilt:
If your errors are template related, take a look at STLfilt:
gccfilter 进行着色和处理 消息的简化。
http://www.mixtion.org/gccfilter/
gccfilter does coloring & simplification of messages.
http://www.mixtion.org/gccfilter/
如果您使用 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.检查 diagcc ,你可以得到这样的东西:
如果您的 gcc ≥ 4.9,您可以使用参数
-fdiagnostics-color=always
。check diagcc out, you can get something like this:
If your gcc ≥ 4.9, you can use argument
-fdiagnostics-color=always
.4年后回答你的问题,这里应该提到clang。
To answer your question 4 years later, clang should be mentioned here.
这是我当前的 hack,主要是在战略位置插入换行符和缩进以及一些额外的注释,但对解决 STL 的冗长问题没有任何作用。
请注意,按照当前实现的情况,如果编译器返回错误,此脚本不会返回错误,因此执行类似的操作将无法正常工作:
(make && ./runApplication)< /代码>。 这肯定可以由具有更好 bash-fu 的人来解决。
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.如果您喜欢 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/
我使用这个名为
colorize
的脚本:然后我就这样调用它(使用 make 或任何构建系统):
我得到类似于 clang 的颜色输出。
I use this script, called
colorize
:Then I just call it like this(using make or whatever build system):
And I get color output similar to clang.