Qt 4.6 + MinGW: suppress warnings for generated code - c++

We are using Axis2 (WSDL2C) to generate *.c/*.h files from WSDLs in order to be able to call webservices with Qt 4.6. But the generated code creates a massive amount of warnings (3 services -> >1k warnings), mostly about uninitialized or unused variables. How can we suppress these warnings properly?
I know I can wrap headers in #pragma to suppress warnings from 3rd party libs, but how to deal with generated code where the warnings come from the implementation?

Add this line to your Qt .pro or .pri file:
QMAKE_CFLAGS += -Wno-unused
It turns off unused warning.

The code generator is Apache, i.e. Open Source. Have you had a peek at the source? Perhaps you can patch that?

Related

How do you keep track of warnings generated while compiling many different source files

I am using GNU g++ to compile an older c++ project with many source files. I am trying to get the project to compile without warnings using -Wall for version c++ versions 11 up to 17.
If I delete the entire build directory and remake everything from scratch, a large list of warnings appears. After fixing warnings generated by a specific file and recompiling, only warnings from that specific file are displayed, since the makefile detects that all other objects are up to date and the .cpp/.h files aren't modified.
Since doing the build from scratch is time consuming. My solution is digging into directories and deleting the objects, so I can recompile and see the warnings. This is okay, but somewhat tedious.
Is there any other solution. Is there a way to force the compiler to exit on a warning as if it was an error? I'm using GNU g++.
I am using -Werror and editing the makefile to add options for compiling only a few source files at a time. I think this is the best way. Thanks everyone.

qmake auto-generated Makefile compiler set incorrectly

We are doing a C++ project for our uni and its final phase is passing the whole thing into a graphical interface using Qt.
We use Qt5.4 and g++-5. These values have been set in the QtCreator project configuration by selecting the appropriate compiler, g++-5, and also adding options in the *.pro file such as -std=c++14 and so on.
Nevertheless we are being stumped by an important issue. No matter what we try, when running qmake so as to auto-generate the precompiled files, in any Makefile generated by it, the compiler is ALWAYS set to g++ and not g++-5. We are at the moment obliged to after using qmake having to change by hand the compiler in the Makefile on our own, even though we have told it EVERYWHERE that we are using g++-5 and not the normal g++.
We have tried solutions like in this question: Using c++14
And also changing the compiler in the mkspecs of the Qt SDK.
Both have been to no avail and we still can't get the auto-generated Makefile to use g++-5 unless we change it by hand.
Is this a Qt issue or are we doing a step incorrectly?
Thanks in advance.
Sorry for all the bother.
It is solved now, I had linked my g++ compiler to g++-5 when I installed it ages ago but had forgotten (both g++ and g++-5 work on my pc, but they are the same) so it wasn't being an error, just my pc configuration getting in the way, thanks for the help though.

Why does cmake ignore ADD(SYSTEM) header files when CXX is defined?

I've bumped into the following annoying issue. I installed g++ via macports on OSX, everything works fine. However, cmake still detects clang++ as the cpp compiler. Therefore, I end up putting
export CXX=/opt/local/bin/g++
in my profile. Now, cmake correctly detects g++ as the compiler. The problem is that all the system headers that I include with
INCLUDE_DIRECTORIES(SYSTEM "/path/to/system/header)
are included as regular headers. In other words, I am getting a whole bunch of warnings (-Wall) which I'd very much like to suppress, since I don't care about warnings in system headers like Boost or Eigen.
Any idea how to address this issue? It's driving me crazy, and I am completely puzzled why adding CXX in the profile results in this behaviour. If I remove the export CXX from my profile and manually set CMAKE_CXX_COMPILER to g++ in the CMakeLists.txt then everything is fine, no more warnings for system files.
I finally figured out a solution, from a somehow randomly found post: http://www.cmake.org/pipermail/cmake/2011-June/044769.html. For some reason, the SYSTEM directive was ignored. Setting
SET(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")
solves it, no more warnings generated for system files.
This is a very peculiar issue that appears only on OS X. On all other systems I tested, INCLUDE_DIRECTORIES(SYSTEM "/path/to/system/header") adds the headers as system headers, without any need to use the SET above.
Using export CXX=/opt/local/bin/g++ with several other system variables not adapted seems a little bit unorthodox, so the weird behavior is maybe not surprising.
I suggest you configure from scratch (=from a clean build directory) your project from cmake-gui, the menu allows you to specify the path to the compiler(s) you want to use. You can also use a custom tool-chain file. I suggest you use cmake-gui, it offers a couple of choice that might solve your problem.
Once you get it right, you can document the equivalent command line instruction for other people building your project.

How to eliminate external lib/third party warnings in GCC [duplicate]

This question already has answers here:
How to suppress GCC warnings from library headers?
(10 answers)
Closed 7 years ago.
In the software project I'm working on, we use certain 3rd party libraries which, sadly, produce annoying gcc warnings.
We are striving to clean all code of warnings, and want to enable the treat-warnings-as-errors (-Werror) flag in GCC.
Is there a way to make these 3rd party generated warnings, which we cannot fix, to disappear?
Use -isystem
Example:
gcc -I./src/ -isystem /usr/include/boost/ -c file.c -o obj/file.o
With -isystem NO warning about boost :D
If you're using CMake, you can achieve this by adding SYSTEM to include_directories:
include_directories(SYSTEM "${LIB_DIR}/Include")
^^^^^^
I presume you are talking about the warnings coming from the 3rd party library headers.
The GCC specific solution would be to create another wrapper header file which has essentially the two lines:
#pragma GCC system_header
#include "real_3rd_party_header.h"
And use the wrapper instead of the original 3rd party header.
Check another SO response detailing the pragma. It essentially tells GCC that this (with recursively included files) is a system header, and no warning messages should be generated.
Otherwise, I'm not aware how one can disable warnings coming from the 3rd party code. Except by the brute force of course: in the build system configure the files to be built with warnings off.
http://www.artima.com/cppsource/codestandards.html
Example 1: A third-party header file.
A library header file that you cannot
change could contain a construct that
causes (probably benign) warnings.
Then wrap the file with your own
version that #includes the original
header and selectively turns off the
noisy warnings for that scope only,
and then #include your wrapper
throughout the rest of your project.

Conditionally disable warnings with qmake/gcc?

I am involved with a software project written in Qt and built with qmake and gcc on Linux. We have to link to a third-party library that is of fairly low quality and spews tons of warnings. I would like to use -W -Wall on our source code, but pass -w to the nasty third-party library to keep the console free of noise and clutter so we can focus on our code quality.
In qmake, is there a way to conditionally add CFLAGS/CXXFLAGS to certain files and libraries?
Jonathan, I think the problem is where your source files are including header files from 3rd party libraries, and you want to switch off the warnings for the latter.
Kevin, i think you can use pragmas to control warnings : gcc diagnostic pragmas
You could add these before and after any #includes for 3rd party libs.
What if you include your library using -isystem.
In the project file e.g.:
QMAKE_CXXFLAGS += -isystem /usr/local/boost_1_44_0
Normally, you'd build the third-party library in a separate directory from your own code, so you would have a different makefile for it, so you could put a different set of flags for that compilation.
If you've mixed the third-party library code with your own code, you have set yourself up for a maintenance nightmare.
Kevin,
qmake CONFIG+=debug QMAKE_CXXFLAGS_WARN_ON=-w QMAKE_CFLAGS_WARN_ON=-w
should do
(use CONFIG+=release if you wish...)
As Martin wrote adding the include directory via
QMAKE_CXXFLAGS += -isystem ...
suppresses warnings just in the respective headers. No need to disable warnings for any source files of your project (or even project-wide) or mess with #pragmas or wrappers files.
Note that if you're using QtCreator you'll still (i.e. additionally) want add the directory to INCLUDEPATH so the indexer picks up the headers.