4

I am new in c++. I am compiling a code source on Qt. I have this warning:

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


I got also these warning:

../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]\n",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)\n",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 (*)\n",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.

How can I disable this warning ?

manlio
  • 18,345
  • 14
  • 76
  • 126
LearnToGrow
  • 1,656
  • 6
  • 30
  • 53

3 Answers3

6

Repeating the previous answer "The answer is in the warning message itself."

"To disable this warning use -Wno-deprecated."

You can specify the compiler flag in the Qt project file (.pro) adding this line:

QMAKE_CXXFLAGS += -Wno-deprecated

P.S. It will be better to fix the code itself

alexeibs
  • 535
  • 3
  • 7
  • Depending on the compiler it might also be necessary to add ``-Wno-deprecated-declarations``. – Hyndrix Sep 10 '16 at 05:27
  • How can I open this *.pro file? (I cannot find it in my project stucture, does it have a specific place in the linux system? Can I open it from the QT GUI somehow?) – bendaf Sep 24 '18 at 10:21
  • @bendaf You can open it in any text editor - Qt Creator, for example. it's usually located in the root of your project directory – alexeibs Sep 24 '18 at 19:59
  • Thanks @alexeibs, I found out, that my problem was that I have opened a Cmake project so I did not have a qt .pro file just the CMakeLists.txt . – bendaf Sep 25 '18 at 07:05
3

The answer is in the warning message itself:

EDIT:

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]

replace iostream.h by iostream C++'s headers nowadays didn't require .h extension anymore.

The Mask
  • 17,007
  • 37
  • 111
  • 185
  • How to disable the warining of unused parameters ? I edited my code – LearnToGrow Mar 28 '14 at 15:59
  • @phdstudent: It seems you're using gcc or gcc-like compiler. In this case to disable a warning you just put a `no` after `W` e.g, `-W-foo` became `-Wno-foo` which turns on and off respectively the `foo` warning name. But to really know about these things you should read your compiler documentatio/manual. – The Mask Mar 28 '14 at 16:41
1

warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char* argv[])
             ^
warning: unused parameter 'argv' [-Wunused-parameter]
int main(int argc, char* argv[])

Change the definition of main in:

int main()
{
  // ...

it's standard compliant.


warning: unused parameter 'junk' [-Wunused-parameter]
void SetConsoleCtrlHandler(void (*func)(int), int junk)

Not naming a parameter is legal also in function implementation. This is useful when the function needs to declare the parameter to have a specific fixed signature, but the parameter is not needed (this may happen for example for a method in a derived class, for a callback function or for a template parameter).

So, if this is the case, you could change the function definition:

void SetConsoleCtrlHandler(void (*func)(int), int)
{
  //...

If you control the header file, fix it! For the ones you don't (system, 3rd party libs...) you can use the -isystem flag (this will make them "system headers" and GCC/CLANG won't report warnings for them).

E.g.

QMAKE_CXXFLAGS += -isystem ...
Community
  • 1
  • 1
manlio
  • 18,345
  • 14
  • 76
  • 126