编译QT项目时使用的警告级别是多少?
当我使用W4进行编译时,我收到了很多警告,例如:
C4127: conditional expression is constant我是否应该在W3上编译,或者在W4上找到其他方法来处理警告,比如:添加一个新的头文件和使用杂注(在这里提到的C++编码标准: 101规则,指南和最佳实践)。
你的实践是什么?
谢谢。
发布于 2010-04-30 20:49:13
我遇到了几年前遇到的完全相同的问题,那就是将编译器设置为4级警告,以捕获尽可能多的潜在问题。当时,我和Qt签订了一份支持合同,问他们为什么他们的代码会产生这么多警告。他们的回应是,他们从来没有强调过他们的代码可以在没有任何警告的情况下编译。只有他们的代码才能正确运行。
经过几次尝试,我开始在Qt头文件周围使用编译指示来禁用警告,如下所示-
#pragma warning(push,3) // drop compiler to level 3 and save current level
#include <QString>
#include <QVariant>
#include <QStack>
#include <QLabel>
#include <QtGui/QTableWidget>
#pragma warning(pop) // restore compiler warning level通过这种方式,您只需在较低的警告级别编译Qt头文件。或者以任何级别来消除警告。您可能仍会显示一些单独的警告,因此可以使用以下命令提高警告级别或禁用单独的警告
#pragma warning(disable: 4700)一些Boost库文件也有这个问题。
发布于 2010-04-30 14:02:47
就我个人而言,我只是使用qmake默认生成的Makefiles。假设我可以相信诺基亚的人会让它生成Makefile,为当前的构建环境做正确的事情。
不过,我确实看到qmake将接受一些关于警告的可选参数:
The level of warning information can be fine-tuned to help you find problems in your project file:
-Wall
qmake will report all known warnings.
-Wnone
No warning information will be generated by qmake.
-Wparser
qmake will only generate parser warnings. This will alert you to common pitfalls and potential problems in the parsing of your project files.
-Wlogic
qmake will warn of common pitfalls and potential problems in your project file. For example, qmake will report whether a file is placed into a list of files multiple times, or if a file cannot be found.发布于 2014-06-26 11:05:07
在.pro文件中使用CONFIG += warn_on。
参见the documentation。
选项
warn_on编译器应该输出尽可能多的警告。如果指定了warn_off,则忽略此项。warn_off编译器应该输出尽可能少的警告。
https://stackoverflow.com/questions/2742514
复制相似问题