如何禁用从gcc出来的未使用的变量警告? [英] How do you disable the unused variable warnings coming out of gcc?

查看:1678
本文介绍了如何禁用从gcc出来的未使用的变量警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道什么开关你传递给gcc编译器关闭未使用的变量警告?我在Windows上提升错误,我不想触摸提升代码:

I'd like to know what switch you pass to the gcc compiler to turn off unused variable warnings? I'm getting errors out of boost on windows and I do not want to touch the boost code:

C:\boost_1_52_0/boost/system/error_code.hpp: At global scope:
C:\boost_1_52_0/boost/system/error_code.hpp:214:36: error: 'boost::system::posix_category' defined but not used [-Werror=unused-variable]
C:\boost_1_52_0/boost/system/error_code.hpp:215:36: error: 'boost::system::errno_ecat' defined but not used [-Werror=unused-variable]
C:\boost_1_52_0/boost/system/error_code.hpp:216:36: error: 'boost::system::native_ecat' defined but not used [-Werror=unused-variable]



我尝试使用 -Wunused-value code> -Wno-未使用的价值但既不抑制上述消息。

I tried using both -Wunused-value and -Wno-unused-value but neither suppressed the messages above.

什么是正确的命令,这里是我的编译行:

What is the right command, here is my compile line:

g++  -g -fno-inline -Wall -Werror -Wextra -Wfloat-equal -Wshadow
-Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wno-conversion 
-Wdisabled-optimization -Wredundant-decls -Wunused-value -Wno-deprecated 
-IC:\\boost_1_52_0 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 
-c -o op.o op.cpp

也许 -Wall 会覆写我的目标?

推荐答案

code> -Wno-unused-variable 开关通常会做到这一点。然而,如果你在项目中关心这些事情,这是一个非常有用的警告。当GCC开始虽然警告你的事情不是在你的代码变得恼人

The -Wno-unused-variable switch usually does the trick. However, that is a very useful warning indeed if you care about these things in your project. It becomes annoying when GCC starts to warn you about things not in your code though.

我建议你保持上的警告,而是使用 - isystem 而不是 -I 用于包括第三方项目的目录。 ,这标志告诉GCC不是要提醒你,你有没有控制权的东西。

I would recommend you keeping the warning on, but use -isystem instead of -I for include directories of third-party projects. That flag tells GCC not to warn you about the stuff you have no control over.

例如,而不是的-IC:\\ boost_1_52_0 ,说 -isystem C:\\boost_1_52_0

帮助。祝你好运!

这篇关于如何禁用从gcc出来的未使用的变量警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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