highlight and filter (gcc) compiler messages

夙愿已清 提交于 2019-11-30 17:28:25

问题


i'm currently refactoring a C-project, throwing about 1000 warnings at me. is there a way to highlight and filter these warnings. (eg make all index warnings red, unused blue, and some other)

most likely some ides can do that, but that's no solution for me.


回答1:


Try the colorgcc Debian package. There are also three other packages I found: Johannes Schlüter's colorgcc, or this package in German, or this Sourceforge project




回答2:


This is really basic, but I've been using grep...

make 2>&1 | grep --color -iP "\^|warning:|error:|"

just to quickly draw the eye to the error line and offending section pointed to by ^.

I've found other methods over-use colour and you end up with the same problem. I guess you could also inject colour escape sequences with sed.




回答3:


Gcc 4.9 seems to have added this feature via the -fdiagnostics-color flag: http://gcc.gnu.org/onlinedocs/gcc/Language-Independent-Options.html#index-fdiagnostics-color-246




回答4:


The warn_summary script is pretty nice

You can get a count of all your warnings, the type and also just print out the warnings without all the other output from gcc.

gcc <...> | tee buildoutput
warn_summary -s 0 -wpass buildoutput
warn_summary -s 0 buildoutput



回答5:


You could pipe the output of your compile through grep:

make 2> error.txt; grep -e error error.txt



回答6:


Compiling in emacs gives you some highlighting. Presumable the details are amenable to customization.

Use M-x compile and issue you usual build command (defaults to make -k).




回答7:


I've been using pretty make, which formats and colorizes gcc output nicely. The indented format for command options is very clear. I did end up hacking it to swap the deprecated popen2 to subprocess.




回答8:


This answer is more about the general approach to reworking old C code.

Large volumes of warnings usually are repetitions of the same small group of warnings because of some errors in header files that are included all over the place by other source code files.

If you're refactoring an old C project, quite often most warning come down to various things such as old K'n'R function dec's, previously allowed casts now being highlighted with a warning, using deprecated functions, etc.

Assuming you're using (g)make to build the project, I'd run the compile using the following command:

gmake 2>&1 | tee results

Then you can have a look at the results file and see what are the most popular warnings you're getting. Start with eliminating all existing warnings before getting on to any refactoring of the code base.

Running the make from within vim gives you lots of possibilities to couple the error and warning messages with the source files.



来源:https://stackoverflow.com/questions/1032237/highlight-and-filter-gcc-compiler-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!