Improving g++ output

2020-02-02 07:54发布

g++ sometimes produces pretty convoluted outputs. Specially when dealing with templates. Is there any tool that makes g++ output more readable? ... at least some color?

It may sound silly to ask this question here, but I've been unable to google my way out of this.

标签: c++ g++
10条回答
放荡不羁爱自由
2楼-- · 2020-02-02 08:30

There's colorgcc, a perl script which wraps the gcc (g++) output with color for easier readability.

As far as the "output" of gcc (g++) I am guessing you're not complaining about the compiled binaries :)

查看更多
别忘想泡老子
3楼-- · 2020-02-02 08:30

There is colorgcc.

查看更多
趁早两清
4楼-- · 2020-02-02 08:32

you can use GilCC which is a Ruby tool that will convert GCC output to color in real-time. It is free and you can customize it to your preference. It is not intrusive as it does not change your gcc setup and you don't have to edit any system files such as .bash. You have to install Ruby and be able to invoke Ruby programs from the command line. Right now you have two options Perl script or GilCC and if you work with Ruby you will like GilCC.

Then whenever you call "GillCC" it will call "make" behind the scenes with your parameters such as "clean", "debug" or "release". for example if normally you call: "make debug" you should call "GilCC debug".

Almost forgot to mention that GilCC has some statistics such as # of warnings and error as well as build time. These things are handy when you are trying to improve your build.

The link to the download page is here.

查看更多
5楼-- · 2020-02-02 08:33

If you use gcc 4.9 or higher there are a couple built-in options:

  • -fmessage-length=n, which optimizes the output for lines of n characters length.
  • -fdiagnostics-color=always, which applies some nice colors.
    (Works fine on linux, not so much on msys)

For more options and exact usage heres the documentation:
https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Message-Formatting-Options.html

查看更多
在下西门庆
6楼-- · 2020-02-02 08:37

When dealing with the STL1, STLFilt comes to the rescue.

On a related note, I also heard that the clang compiler produces by itself much better error messages in general.


Nitpickers' corner

  1. Actually, not the SGI STL, but the parts of it that have been adopted in the C++ standard and are part of the standard library.
查看更多
贪生不怕死
7楼-- · 2020-02-02 08:37

there is my personal function:

colorgcc()
{
perl -wln -M'Term::ANSIColor' -e '
m/not found$/ and print "\e[1;30m$`\e[0m", "$&", "\e[0m"
or
m/found$/ and print "\e[1;30m$`\e[0;32m", "$&", "\e[0m"
or
m/yes$/ and print "\e[1;30m$`\e[0;32m", "$&", "\e[0m"
or
m/no$/ and print "\e[1;30m$`\e[0m", "$&", "\e[0m"
or
m/ Error |error:/i and print "\e[1;91m", "$_", "\e[0m"
or
m/ Warning |warning:/i and print "\e[0;33m", "$_", "\e[0m"
or
m/nsinstall / and print "\e[0;36m", "$_", "\e[0m"
or
m/Linking |link: |\.a\b/ and print "\e[1;36m", "$_", "\e[0m"
or
m/Building|gcc|g++|\bCC\b|\bcc\b/ and print "\e[1;30m", "$_", "\e[0m"
or
print; '
}
查看更多
登录 后发表回答