Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a count of errors and warnings from gcc and g++?

I've skimmed through the $ man gcc and $ man g++ but haven't found something that would print the error and warning counts. But I see that Emacs can print the error counts and warning counts in the *compilation* buffer. So, there must be an option in gcc and g++ that I'm missing, cause I don't think Emacs would itself implement error count, that's just too much work.

How do I get a count of errors and warnings from gcc and g++?

like image 358
kadekai Avatar asked May 03 '19 13:05

kadekai


People also ask

How do I make GCC warnings as errors?

You can use the -Werror compiler flag to turn all or some warnings into errors.

Which GCC flag is used to enable all compiler warnings?

gcc -Wall enables all compiler's warning messages. This option should always be used, in order to generate better code.

Which option can be used to display compiler warnings?

You can use a #pragma warning directive to control the level of warning that's reported at compile time in specific source files. Warning pragma directives in source code are unaffected by the /w option.

How do you use werror?

You can do this by specifying Werror=warning-name , which will cause that specific warning to generate an error. For example, a warning that I promote to an error is -Wreturn-type .


1 Answers

It doesn't make much sense to count errors in gcc, because usually it runs on one file at a time and a project is usually many files, so there are many invocations of gcc to build a project. Potentially there are many errors in different files so it makes sense that whatever runs gcc (e.g. make, or in turn Emacs which runs make) should keep track of the errors. Indeed, when you run M-x compile, Emacs is the thing counting the errors. Open compile.el (M-x find-library RET compile RET) and look at the variable compilation-num-errors-found, which is what gets added to the mode line (along with similar counts for warnings and infos). It's not super straightforward how those variables get updated, but ultimately it's just matching regexps on the compiler output.

like image 98
jpkotta Avatar answered Nov 15 '22 08:11

jpkotta