问题描述
我想知道您传递给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]
我尝试同时使用-未使用值
和 -Wno-unused-value
,但都没有抑制上面的消息。
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
也许-墙
覆盖我的目标吗?
推荐答案
-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
。
希望它帮助。祝你好运!
Hope it helps. Good Luck!
这篇关于如何禁用我不想编辑的第三方代码中来自gcc的未使用的变量警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!