5

How would I manage to highlight errors and warnings generated by ninja when I compile cpp? When I get errors, I only see white text, and it would improve readability if I could highlight errors and warnings.

user4581301
  • 33,082
  • 7
  • 33
  • 54
Mechap
  • 319
  • 3
  • 9
  • 1
    Your question is highly unclear. `How would I manage` What/how do you mean to "manage" the output? `to highlight errors` highlight how? What do you mean by that? `generated by ninja` Are you sure that ninja generates the errors, and not your compiler? Are you using cmake or writing ninja files by yourself? Most probably you want to read Most probably you want to https://medium.com/@alasher/colored-c-compiler-output-with-ninja-clang-gcc-10bfe7f2b949 . – KamilCuk Aug 11 '20 at 00:27
  • Ninja errors are in red color already. You may want to separate stdout & stderr though. https://stackoverflow.com/questions/637827/redirect-stderr-and-stdout-in-bash –  Aug 11 '20 at 16:45

2 Answers2

5

You do not see errors because the compiler notice it is not outputint its message to a terminal, so it defaults to no color. With GCC you can force colored output with the -fdiagnostics-color=always command line option.

Oliv
  • 17,610
  • 1
  • 29
  • 72
2

In case there is still someone out there struggling with this (like how I was not too long ago), here's what worked for me:

As this link and Oliv highlighted out, one needs to force Ninja to use colors (via -fdiagnostics-color on GCC>=4.9 or -fcolor-diagnostics for Clang)

This will force Ninja to format the specific output elements with the format defined in the GCC_COLORS environment variable.

FYI: If this variable is an empty string, then there is no coloring at all.

On how to configure this, see https://gcc.gnu.org/onlinedocs/gcc-5.1.0/gcc/Language-Independent-Options.html, where the default configuration is also included as an example.

David
  • 21
  • 2