Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Optimized compiling with Qt
Forum Update on Monday, May 27th 2025

[SOLVED] Optimized compiling with Qt

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 15.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    soroush
    wrote on 20 Oct 2011, 20:43 last edited by
    #1

    Hello

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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on 20 Oct 2011, 21:09 last edited by
      #2

      You can try

      @

      remove possible other optimization flags

      QMAKE_CFLAGS_RELEASE -= -O
      QMAKE_CFLAGS_RELEASE -= -O1
      QMAKE_CFLAGS_RELEASE -= -O2

      add the desired -O3 if not present

      QMAKE_CFLAGS_RELEASE *= -O3
      @

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • S Offline
        S Offline
        soroush
        wrote on 20 Oct 2011, 21:20 last edited by
        #3

        [quote author="Volker" date="1319144953"]You can try

        @

        remove possible other optimization flags

        QMAKE_CFLAGS_RELEASE -= -O
        QMAKE_CFLAGS_RELEASE -= -O1
        QMAKE_CFLAGS_RELEASE -= -O2

        add the desired -O3 if not present

        QMAKE_CFLAGS_RELEASE *= -O3
        @

        [/quote]

        Thank you. but didn't worked for C++. I also do this:
        @
        QMAKE_CXXFLAGS_RELEASE -= -O
        QMAKE_CXXFLAGS_RELEASE -= -O1
        QMAKE_CXXFLAGS_RELEASE -= -O2

        QMAKE_CXXFLAGS_RELEASE *= -O3
        @

        Is this correct?

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

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on 20 Oct 2011, 21:30 last edited by
          #4

          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

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • S Offline
            S Offline
            soroush
            wrote on 26 Oct 2011, 07:11 last edited by
            #5

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

            qmake configuration for linux-g++

            Written for GNU/Linux platforms that have both lib and lib64 directories,

            like the AMD Opteron.

            MAKEFILE_GENERATOR = UNIX
            TARGET_PLATFORM = unix
            TEMPLATE = app
            CONFIG += qt warn_on release incremental link_prl
            QT += core gui
            QMAKE_INCREMENTAL_STYLE = sublib
            QMAKE_CFLAGS -= -O2
            QMAKE_CFLAGS -= -O1
            QMAKE_CXXFLAGS -= -O2
            QMAKE_CXXFLAGS -= -O1
            QMAKE_CFLAGS = -m64 -O3
            QMAKE_LFLAGS = -m64 -O3
            QMAKE_CXXFLAGS = -m64 -O3

            include(../common/g++.conf)
            include(../common/linux.conf)

            QMAKE_LIBDIR_X11 = /usr/X11R6/lib64
            QMAKE_LIBDIR_OPENGL = /usr/X11R6/lib64

            load(qt_config)
            @

            God bless gcc ;)

            1 Reply Last reply
            2

            1/5

            20 Oct 2011, 20:43

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved