14

I am new to cmake and gcc. The first assignment in my new role in the company was to clean the errors from our linux compilation I did most of it, and now the only warning I see is

cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C [enabled by default]

I want wither to suppress the warning or to solve the issue in the cmake file. Unfortunately, I still haven't found the correct -Wno-xxx statement that fits here.

Thanks!

user4815162342
  • 141,790
  • 18
  • 296
  • 355
amitfr
  • 1,033
  • 1
  • 9
  • 29

1 Answers1

14

Code issue warnings can be silenced with -Wno-xxx options because sometimes you don't have control over the source code. But a warning telling you that a command-line option is incorrect cannot be silenced with yet another command-line option — if you can affect compiler invocation, then why not just remove the incorrect option?

This particular warning tells you that you cannot set standard to C++11 when compiling C code. To get rid of it, find where -std=c++11 is defined in the build configuration, and make sure it is only applied to C++ compilation, and not for C. For example, move it from CFLAGS to CXXFLAGS, or cmake's equivalent thereof.

user4815162342
  • 141,790
  • 18
  • 296
  • 355
  • I am able to get rid of this comment if I disable the warning "Warn if '0' is used as a null pointer constant[-Wzero-as-null-pointer-const]. Not sure how it is related – Jon Wheelock Apr 08 '16 at 04:48
  • @JonWheelock This question is about the warning produced when using the `-std=c++11` when compiling C. According to [the documentation](https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html), `-Wno-zero-as-null-pointer-const` is a C++ option, and is as not even recognized by gcc compiling C files. – user4815162342 Apr 08 '16 at 14:37