How to suppress warnings in qmake for clang++
-
Hi,
I built Qt 4.8.0 using XCode 4.2. Now i'm trying to build a library which generates many unused variable warnings. I tried to add this lines to library's pro file but this doesn't suppress any warnings.
@clang* {
QMAKE_CXXFLAGS += -Wno-unused-variable -Wno-deprecated-writable-strings
}@So, how can i suppress these warnings?
-
These warnings are not from a Qt compilation. This is a 3rd party library project which my project is depend on it.
A source code on this library generates thousands of warnings. I don't want to see these warnings while compiling my project. I disabled these warnings in MSVC compiler using these lines in that library pro file:
@win32-msvc* {
QMAKE_CXXFLAGS += /wd4100 /wd4101 /wd4102 /wd4189 /wd4996
}@Now i need to port my project to Mac OS X Lion. And i cannot suppress these warnings.
-
@koahnig: The fact that Qt triggers a lot of warnings is actually quite annoying. From a code quality perspective, warnings have a urgency similar to errors, IMO. Often the only warnings that are impossible to get rid off are the ones generated by Qt itself.
-
If possible at all: warnings should be fixed instead of ignored. Seriously. If you are not going to use a variable, be explicit about and either:
remove the argument completely from the function, or
remove the name of the argument from the function, or
use a construct like Q_UNUSED(myVariable) to be explicit about you not using the argument.
But don't just ignore the warning. Warnings are there for a reason. The may point to more severe issues or may develop into real problems later on.
-
Thanks for the info but I already know these rule of thumbs. I actually follow these rules. But this is not my project. This is a third party library and i'm not allowed to edit these library's source code. It's library writer's responsibility. I just want to suppress these warnings by editing pro file.
In gcc @QMAKE_CXXFLAGS = -Wno-unused-variable@ should do the trick but in ==clang++== this method didn't work.
Any suggestions?
-
[quote author="miroslav" date="1324471099"]@koahnig: The fact that Qt triggers a lot of warnings is actually quite annoying. From a code quality perspective, warnings have a urgency similar to errors, IMO. Often the only warnings that are impossible to get rid off are the ones generated by Qt itself.[/quote]
Yes, I agree completely. The first time I was compiling Qt libs it was a shock to me when seeing the warnings. However, I (have) arranged myself with it.
I am certainly agreeing also with Andre. He is summarizing my coding ethics.
My answer was refering to the compilation of the Qt libs.
On the other hand I find it more than a bit annoying that I have to clatter my code with pragmas for ignoring warnings when a Qt header is included. IMHO that is a nogo, but on an individual basis you are fighting against windmills there.
-
Here's my console output for an unexpected warning generation:
@clang++ -c -pipe -Wno-unused-variable -Wno-deprecated-writable-strings -O2 -arch x86_64 -fPIC -Wall -W -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.8.0/mkspecs/unsupported/macx-clang -I. -I/usr/local/Trolltech/Qt-4.8.0/lib/QtCore.framework/Versions/4/Headers -I/usr/local/Trolltech/Qt-4.8.0/include/QtCore -I/usr/local/Trolltech/Qt-4.8.0/include -I. -I. -F/usr/local/Trolltech/Qt-4.8.0/lib -o ltkcpp_genout.o ltkcpp_genout.cpp
In file included from ltkcpp_genout.cpp:27:
./out_ltkcpp.inc:1312:3: warning: unused label 'missing' [-Wunused-label]
missing:
^
./out_ltkcpp.inc:1321:33: warning: unused variable 'pType' [-Wunused-variable]
const CTypeDescriptor * pType;
^@As you can see i passed ==-Wno-unused-variable== parameter but clang++ still generates unused-variable error.
-
The problem with CONFIG += warn_off is that you don't get any warnings, but without it I get hundreds of useless warnings from a library. Adding -W flags to CPPFLAGS or QMAKE_CXXFLAGS doesn't help, because the warn_on generates a -Wall that comes after them.
SOLUTION: In the .pro file:
QMAKE_CXXFLAGS_WARN_ON = -Wall -Wno-unused-parameterThis sets the flags used when warn_on appears in CONFIG (the default). Now they are in the right order.
-
+1 for this question. I have exactly the same problem. The reason why I want to get rid of these warnings is that I want to see no warnings except in the cases that are actually relevant. If I keep seeing irrelevant warnings, I will tend to ignore them and probably fail to see the relevant ones.
Unfortunately, I can't seem to get rid of them. The platform is win32, I tried each of these lines (separately, not all at one), to no avail:
@
QMAKE_CXXFLAGS += -wd4100
QMAKE_CXXFLAGS += -Wno-unused-parameter
QMAKE_CXXFLAGS += /wd4100 /wd4101 /wd4102 /wd4189 /wd4996
QMAKE_CXXFLAGS_WARN_ON = -Wall -Wno-unused-parameter
QMAKE_CXXFLAGS += -wd4100 -wd4101 -wd4102 -wd4189 -wd4996
@With the last line above, the compile output looks like this:
@
cl -c -nologo -Zm200 -Zc:wchar_t -FS -wd4100 -wd4101 -wd4102 -wd4189 -wd4996 -Zi -MDd -GR -W3 -w34100 -w34189 -EHsc /Fddebug\FirstQtTest.pdb -DUNICODE -DWIN32more defines and includes follow here
@
There is no -Wall argument in my case, still it doesn't work. Any ideas?
-
The problem with CONFIG += warn_off is that you don't get any warnings, but without it I get hundreds of useless warnings from a library. Adding -W flags to CPPFLAGS or QMAKE_CXXFLAGS doesn't help, because the warn_on generates a -Wall that comes after them.
SOLUTION: In the .pro file:
QMAKE_CXXFLAGS_WARN_ON = -Wall -Wno-unused-parameterThis sets the flags used when warn_on appears in CONFIG (the default). Now they are in the right order.
@tjrob said:
SOLUTION: In the .pro file:
QMAKE_CXXFLAGS_WARN_ON = -Wall -Wno-unused-parameterThis sets the flags used when warn_on appears in CONFIG (the default). Now they are in the right order.
This one worked for me ! Thanks a lot ! Removing particular warnings that are generated by external libraries is very useful to still be able to see important ones. When possible I prefer to add specific pragmas when including headers but it's not always possible