Tho*_*ker 7 c gcc c-preprocessor preprocessor-directive
在C/C++代码中我尝试移植,包括一个不赞成使用的系统头:
从标题:
#ifdef __GNUC__
#warning "this header is deprecated"
#endif
Run Code Online (Sandbox Code Playgroud)
当我们在这里编译时gcc -Wall -Werror,编译停止.从长远来看,替换使用已弃用的函数是最好的,但是现在我想禁用此警告.
编译时没有任何-Werror作用,但由于这是完全自动化构建过程的一部分,我宁愿不这样做.
包括与头#undef荷兰国际集团__GNUC__之前和#define之后荷兰国际集团这是一种可能,但我担心的包含的头里面的副作用.
有没有办法禁用#warning或放松-Werror一个标题?
您可以使用(GCC特定的)诊断编译指示执行此操作
如果您使用以下内容包围include,它将禁用由此引起的任何警告#warning.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcpp"
#include "header.h"
#pragma GCC diagnostic pop
Run Code Online (Sandbox Code Playgroud)
请注意,如果您更改上面的ignoredto warning,编译器仍会打印警告 - 它只是不对-Werror它们的标志执行操作.
| 归档时间: |
|
| 查看次数: |
599 次 |
| 最近记录: |