更新时间:2023-11-05 16:59:46
我不熟悉与Tensilica公司的Xtensa编译器( XT-XCC
),但与标准的 GCC
您可以使用
I am not familiar with Tensilica xtensa compiler (xt-xcc
), but with standard gcc
you can use
#pragma GCC diagnostic warning "-Wcpp"
,使指令#warning
简单的警告的问题(不是因为 -Werror
错误)。为了使效果暂时的,你可以拥抱这个的#pragma
和指令#warning
之间的# GCC编译诊断推
和的#pragma GCC诊断弹出
。
to make #warning
a matter of simple warning (not an error because of -Werror
). To make the effect temporary, you can embrace this #pragma
and the #warning
between #pragma GCC diagnostic push
and #pragma GCC diagnostic pop
.
当我编译包含的文件以下
When I compile a file containing the following
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wcpp"
#warning one
#pragma GCC diagnostic pop
#warning two
与 -Werror
使用 GCC
4.6.1(命令 GCC -c -Werror警告-test.c以
),我得到以下的输出:
with -Werror
using gcc
4.6.1 (command gcc -c -Werror warning-test.c
), I get the following output:
warning-test.c:3:2: warning: #warning one [-Wcpp]
warning-test.c:6:2: error: #warning two [-Werror=cpp]
cc1: all warnings being treated as errors
当我删除第二个指令#warning
编译不会被错误而中断。
When I remove the second #warning
the compilation is not interrupted by error.
您也可以使用 -Werror -Wno错误= CPP
更换你的 -Werror
编译器选项。我不知道还有什么其他影响 CPP
警告类别包括:(你可能有一个合法的指令#warning
在一些要捕捉尽可能错误以外的地方),所以暂时禁用错误的特定指令#warning
和恢复设置立即满足看来你的要求更精确的方法了。
You can also replace your -Werror
compiler options with -Werror -Wno-error=cpp
. I am not aware what other effects the cpp
category of warnings include (and you might have a legitimate #warning
in some other place that you want to catch as error), so temporarily disabling the error for a specific #warning
and restoring the settings immediately after seems more accurate method of meeting your requirements.
修改(2016):
使用 GCC
版本4.8.4和4.9.2给出了pretty很多相同的行为(只有源行还打印出来)。但是,使用 GCC
版本5.0.1(包含在Ubuntu 15.04 $ P $租赁前的版本)会给两个警告,除非选择 = -Werror CPP
也包括在内。如此看来, -Werror
用新的gcc已经不意味着 = -Werror CPP
像以前一样,它必须是如果需要分开设置。
Edit (2016):
Using gcc
versions 4.8.4 and 4.9.2 gives pretty much the same behavior (only the source line is printed out additionally). But using gcc
version 5.0.1 (prerelease version included in Ubuntu 15.04) will give two warnings unless option -Werror=cpp
is included as well. So it seems that -Werror
with newer gcc does not anymore imply -Werror=cpp
like before and it needs to be provided separately if desired.