且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何禁用GCC警告" CC1:警告:命令行选项'-std = C ++ 11'是有效的C ++ / ObjC ++而不是C [默认启用] QUOT;

更新时间:2022-02-01 00:57:54

code发出警告可与沉默 -Wno-XXX 选项,因为有时你不吨有超过源$ C ​​$ C控制。但是,一个警告信息,告诉你一个的命令行选项的不正确,不能用另一个命令行选项沉默 - 如果你能影响编译器调用,那么为什么不直接删除不正确的选项。

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?

这特别的警告,告诉您编译C code时,你可以不设置标准C ++ 11。为了摆脱它,发现其中 -std = C ++ 11 在生成配置定义,并确保它仅适用于C ++编译,并没有对C例如,从 CFLAGS 移至 CXXFLAGS ,或CMake的的等同物。

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.