Search code examples
gcc-warningcompiler-flags

Meaning of the g++ flags "-Wall", " -W", and "-Werror"


What are these and what do they do?

  • -Wall
  • -W
  • -Werror

I am using the terminal in Ubuntu to compile programs with this command:

g++ -Wall -W -Werror main.cpp -o exec

What is the explanation?


Solution

    • -Wall: enable a set of warning, but actually not all.
    • -W: enable extra warnings. It's advised to use -Wextra instead which has the same meaning
    • -Werror: every warning is treated as an error.

    See GCC documentation: 3.8 Options to Request or Suppress Warnings