我是C ++的新手。 我正在Qt上编译代码源。 我有这个警告:
In file included from ../ListAllPrsilicaCameras/main.cpp:3:
In file included from /usr/include/c++/4.2.1/backward/iostream.h:31:
/usr/include/c++/4.2.1/backward/backward_warning.h:32:2: warning: This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated. [-W#warnings]
#warning This file includes at least one deprecated or antiquated header.
^ 1 warning generated
我也收到这些警告:
../ListCamerasProsilicaII/main.cpp:79:51: warning: unused parameter 'junk' [-Wunused-parameter]
void SetConsoleCtrlHandler(void (*func)(int), int junk)
^
../ListCamerasProsilicaII/main.cpp:89:23: warning: unused parameter 'Signo' [-Wunused-parameter]
void CtrlCHandler(int Signo)
^
../ListCamerasProsilicaII/main.cpp:140:57: warning: flag ' ' results in undefined behavior with 'u' conversion specifier [-Wformat]
printf("%s - %8s - Unique ID = % 8lu IP@ = %15s [%s]
",cameraList[i].SerialString,
~^~~~
../ListCamerasProsilicaII/main.cpp:147:57: warning: flag ' ' results in undefined behavior with 'u' conversion specifier [-Wformat]
clang++ -headerpad_max_install_names -mmacosx-version-min=10.6 -o ListCamerasProsilicaII main.o -L/opt/local/lib/ -lPvAPI -lPvJNI -L/opt/local/lib -lJPEG -F/Users/rafikgouiaa/Qt//5.0.2/clang_64/lib -framework QtCore
printf("%s - %8s - Unique ID = % 8lu (unavailable, %u)
",cameraList[i].SerialString,
~^~~~
../ListCamerasProsilicaII/main.cpp:152:53: warning: flag ' ' results in undefined behavior with 'u' conversion specifier [-Wformat]
printf("%s - %8s - Unique ID = % 8lu (*)
",cameraList[i].SerialString,
~^~~~
../ListCamerasProsilicaII/main.cpp:171:14: warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char* argv[])
^
../ListCamerasProsilicaII/main.cpp:171:26: warning: unused parameter 'argv' [-Wunused-parameter]
int main(int argc, char* argv[])
^
7 warnings generated.
如何禁用此警告?
不要做,解决它! -特别是当我刚接触C ++时
该修复程序可能是#include 而不是(!)
重复上一个答案"答案在警告消息本身中。"
"To disable this warning use -Wno-deprecated."
您可以在Qt项目文件(.pro)中指定编译器标志,并添加以下行:
QMAKE_CXXFLAGS += -Wno-deprecated
附言修复代码本身会更好
根据编译器的不同,可能还需要添加-Wno-deprecated-declarations。
如何打开此* .pro文件? (我无法在项目结构中找到它,它在linux系统中是否有特定位置?可以通过QT GUI打开它吗?)
@bendaf您可以在任何文本编辑器-例如Qt Creator中打开它。 它通常位于项目目录的根目录中
感谢@alexeibs,我发现我的问题是我打开了一个Cmake项目,所以我没有qt .pro文件,只有CMakeLists.txt。
答案在警告消息本身中:
编辑:
warning: This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of
the deprecated header . To disable this warning use
-Wno-deprecated. [-W#warnings]
如今,用iostream替换iostream.h的C ++标头不再需要.h扩展名。
如何禁用未使用参数的警告? 我编辑了代码
@phdstudent:您似乎正在使用gcc或类似gcc的编译器。 在这种情况下,要禁用警告,只需在W之后放置一个no,例如-W-foo变为-Wno-foo,分别打开和关闭foo警告名称。 但是要真正了解这些事情,您应该阅读编译器文档/手册。
warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char* argv[])
^
warning: unused parameter 'argv' [-Wunused-parameter]
int main(int argc, char* argv[])
在以下位置更改main的定义:
int main()
{
// ...
它符合标准。
warning: unused parameter 'junk' [-Wunused-parameter]
void SetConsoleCtrlHandler(void (*func)(int), int junk)
在函数实现中,不命名参数也是合法的。当函数需要声明参数具有特定的固定签名但不需要参数时,这很有用(例如,对于派生类中的方法,回调函数或模板参数,可能会发生这种情况)。
因此,在这种情况下,您可以更改函数定义:
void SetConsoleCtrlHandler(void (*func)(int), int)
{
//...
如果您控制头文件,请修复它!对于您不喜欢的那些文件(系统,第三方库...),可以使用-isystem标志(这将使它们成为"系统头文件",而GCC / CLANG将不会为它们报告警告)。
例如。
QMAKE_CXXFLAGS += -isystem ...