-Werror会导致编译器停止指令#warning。我能做些什么,以prevent呢? [英] -Werror causes compiler to stop on #warning. What can I do to prevent this?

查看:2933
本文介绍了-Werror会导致编译器停止指令#warning。我能做些什么,以prevent呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想它停止对警告。但我也想打印出一些信息消息(如回来,并实现这个!)。

First off, I want it to stop on warnings. But I also want to print out some informative messages (like "Come back and implement this!").

不幸的是,我的编译器不支持 #info #message #编译消息()

Unfortunately, my compiler doesn't support #info, #message, #pragma message(), etc.

我知道有 -Wno错误=<东西> ,但我的谷歌-foo是弱,我似乎无法找出<&东西GT; 指令#warning 。我试过 -Wno错误=警告,而只是说有没有 -Wwarning 。同样的,警告

I know there's -Wno-error=<something>, but my google-foo is weak, and I can't seem to find out the <something> for #warning. I've tried -Wno-error=warning, and that just says "there's no -Wwarning". Same with "warn".

有什么建议?

有关它的价值,我用的是什么Tensilica公司的Xtensa编译器,XT-XCC,这似乎是一个GNU的衍生物,或至少使用GNU前端。这是8.0.0版本。

For what its worth, I'm using the Tensilica xtensa compiler, xt-xcc, which appears to be a gnu derivative, or at least uses the gnu front end. It's version 8.0.0.

推荐答案

我不熟悉与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.

这篇关于-Werror会导致编译器停止指令#warning。我能做些什么,以prevent呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆