How to disable warning in g++ in Linux?

Printer-friendly versionPDF version
When you embed an .xpm file to some C++ project in Linux, you will get tons of harmless warnings.

warning: deprecated conversion from string constant to ‘char*’

You can disable such warning in the project on global basis, by adding -Wno-write-strings to the g++ command line arguments.
But, there a better way, to disable warnings for a per file basis using pragma directives in g++:

#pragma GCC diagnostic ignored "-Wwrite-strings"
#include "logo.xpm"
#pragma GCC diagnostic warning "-Wwrite-strings"

List of GCC options to request or suppress warnings can be found on Red Hat website.
Visual Studio also supports similar pragma directives to disable particular warning messages.
Your rating: None Average: 3.3 (3 votes)