December 21, 2011

BerkDemirkir BerkDemirkir
Lab Rat
7 posts

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.

  1. clang* {
  2.     QMAKE_CXXFLAGS += -Wno-unused-variable -Wno-deprecated-writable-strings
  3. }

So, how can i suppress these warnings?

10 replies

December 21, 2011

koahnig koahnig
Mad Scientist
2106 posts

Qt compilations are triggering quite a number of warnings independent of the compiler used. Most people choose to ignore them. Typically they do not cause any harm.

Why is it so important for you to switch off these warnings?

December 21, 2011

BerkDemirkir BerkDemirkir
Lab Rat
7 posts

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:

  1. win32-msvc* {
  2.     QMAKE_CXXFLAGS += /wd4100 /wd4101 /wd4102 /wd4189 /wd4996
  3. }

Now i need to port my project to Mac OS X Lion. And i cannot suppress these warnings.

December 21, 2011

miroslav miroslav
Ant Farmer
228 posts

@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.

 Signature 

Mirko Boehm | .(JavaScript must be enabled to view this email address) | KDE e.V.
FSFE Fellow
Qt Certified Specialist

December 21, 2011

Andre Andre
Area 51 Engineer
6031 posts

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:

  1. remove the argument completely from the function, or
  2. remove the name of the argument from the function, or
  3. 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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

December 21, 2011

BerkDemirkir BerkDemirkir
Lab Rat
7 posts

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

  1. QMAKE_CXXFLAGS = -Wno-unused-variable
should do the trick but in clang++ this method didn’t work.

Any suggestions?

December 21, 2011

koahnig koahnig
Mad Scientist
2106 posts
miroslav wrote:
@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.

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.

December 21, 2011

miroslav miroslav
Ant Farmer
228 posts

Agreed. I do understand that it is hard to make sure no warnings are issued by any compiler. The issue could get a bit more focus, though.

 Signature 

Mirko Boehm | .(JavaScript must be enabled to view this email address) | KDE e.V.
FSFE Fellow
Qt Certified Specialist

December 21, 2011

BerkDemirkir BerkDemirkir
Lab Rat
7 posts

Here’s my console output for an unexpected warning generation:

  1. 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
  2. In file included from ltkcpp_genout.cpp:27:
  3. ./out_ltkcpp.inc:1312:3: warning: unused label 'missing' [-Wunused-label]
  4.   missing:
  5.   ^
  6. ./out_ltkcpp.inc:1321:33: warning: unused variable 'pType' [-Wunused-variable]
  7.     const CTypeDescriptor *     pType;
  8.                                 ^

As you can see i passed -Wno-unused-variable parameter but clang++ still generates unused-variable error.

December 21, 2011

koahnig koahnig
Mad Scientist
2106 posts

Just poking in the dark. But I have noticed that there is a -Wall after -Wno-unused-variable.
Could it be that you switching off the warning and switching it on with -Wall ?
I do not know this compiler.

December 21, 2011

BerkDemirkir BerkDemirkir
Lab Rat
7 posts

Oh! Yes that’s what i’m missing. @koahnig Thank you very much. I should avoid using warn_on CONFIG directive.

 
  ‹‹ QNetworkaccessmanager - post      Dependent Parallel states in Qt Statemachine ››

You must log in to post a reply. Not a member yet? Register here!