3N4N
3N4N

Reputation: 619

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++?

Upvotes: 6

Views: 1932

Answers (1)

jpkotta
jpkotta

Reputation: 9417

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.

Upvotes: 1

Related Questions