October 20, 2011

soroush soroush
Ant Farmer
814 posts

[SOLVED] Optimized compiling with Qt

 

Hello

How do I apply third level optimization (-O3) for g++ compiler in a Qt project? Setting CXXFLAGS didn’t help.

4 replies

October 20, 2011

Volker Volker
Ant Farmer
5428 posts

You can try

  1. # remove possible other optimization flags
  2. QMAKE_CFLAGS_RELEASE -= -O
  3. QMAKE_CFLAGS_RELEASE -= -O1
  4. QMAKE_CFLAGS_RELEASE -= -O2
  5.  
  6. # add the desired -O3 if not present
  7. QMAKE_CFLAGS_RELEASE *= -O3

October 20, 2011

soroush soroush
Ant Farmer
814 posts

Volker wrote:
You can try

  1. # remove possible other optimization flags
  2. QMAKE_CFLAGS_RELEASE -= -O
  3. QMAKE_CFLAGS_RELEASE -= -O1
  4. QMAKE_CFLAGS_RELEASE -= -O2
  5.  
  6. # add the desired -O3 if not present
  7. QMAKE_CFLAGS_RELEASE *= -O3

Thank you. but didn’t worked for C++. I also do this:

  1. QMAKE_CXXFLAGS_RELEASE -= -O
  2. QMAKE_CXXFLAGS_RELEASE -= -O1
  3. QMAKE_CXXFLAGS_RELEASE -= -O2
  4.  
  5. QMAKE_CXXFLAGS_RELEASE *= -O3

Is this correct?

Now programs runs a little faster than previous. (should I also re-compile OpenCV and Qt?)

October 20, 2011

Volker Volker
Ant Farmer
5428 posts

Yes, that’s the variable for C++.

Qt itself, and OpenCV are not affected by the change in your project settings, that’s right. I’m not sure if you will gain that much speed by switching to -O3. The trolls usually go for sane defaults :) But you will only see if you try.

In case you rebuild Qt, I recommend changing that variable setting in the make spec you use. It’s in /path/to/qt/sources/mkspecs

October 26, 2011

soroush soroush
Ant Farmer
814 posts

I recompiled Qt and OpenCV with -O3 flags (takes 9 hours) and then recompile my program with -O3 flag too.

I can’t believe the results! There was only 8 frames per second with normal configuration…. Now it’s 38 frames per second :)
This is my qmake.conf:

  1. #
  2. # qmake configuration for linux-g++
  3. #
  4. # Written for GNU/Linux platforms that have both lib and lib64 directories,
  5. # like the AMD Opteron.
  6. #
  7.  
  8. MAKEFILE_GENERATOR = UNIX
  9. TARGET_PLATFORM  = unix
  10. TEMPLATE  = app
  11. CONFIG   += qt warn_on release incremental link_prl
  12. QT   += core gui
  13. QMAKE_INCREMENTAL_STYLE = sublib
  14. QMAKE_CFLAGS  -= -O2
  15. QMAKE_CFLAGS  -= -O1
  16. QMAKE_CXXFLAGS  -= -O2
  17. QMAKE_CXXFLAGS  -= -O1
  18. QMAKE_CFLAGS  = -m64 -O3
  19. QMAKE_LFLAGS  = -m64 -O3
  20. QMAKE_CXXFLAGS  = -m64 -O3
  21.  
  22.  
  23. include(../common/g++.conf)
  24. include(../common/linux.conf)
  25.  
  26. QMAKE_LIBDIR_X11      = /usr/X11R6/lib64
  27. QMAKE_LIBDIR_OPENGL   = /usr/X11R6/lib64
  28.  
  29. load(qt_config)

God bless gcc ;)

 
  ‹‹ Failed at rewriting a simple HTTP request with QNetworkAccessManager (formely written with curl)      Dynamic text sizing and alignment based on screen resolution ››

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