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. How can I disable compiler optimizations for a release build?
Forum Update on Monday, May 27th 2025

How can I disable compiler optimizations for a release build?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmakewindowsoptimization
1 Posts 1 Posters 671 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.
  • Guy GizmoG Offline
    Guy GizmoG Offline
    Guy Gizmo
    wrote on last edited by
    #1

    I'm trying to build an app in Windows with Qt 6.2.1, qmake, and the Visual Studio 2019 C++ compiler. I want to build a release build with compiler optimizations turned off completely, i.e. passing in the -Od command line argument.

    However, I cannot for the life of me get qmake to do this! It seems to always add in '-O2' no matter what I do.

    First of all, adding QMAKE_CXXFLAGS_RELEASE += -Od has no effect whatsoever, which already is odd. If I use QMAKE_CXXFLAGS instead it works. I am most definitely building a release build, not a debug build.

    I eventually tried adding the following to my .pro file to no avail:

    message($$QMAKE_CFLAGS)
    message($$QMAKE_CFLAGS_RELEASE)
    message($$QMAKE_CXXFLAGS)
    message($$QMAKE_CXXFLAGS_RELEASE)
    QMAKE_CFLAGS -= -O2
    QMAKE_CFLAGS_RELEASE -= -O2
    QMAKE_CXXFLAGS -= -O2
    QMAKE_CXXFLAGS_RELEASE -= -O2
    QMAKE_CFLAGS -= /O2
    QMAKE_CFLAGS_RELEASE -= /O2
    QMAKE_CXXFLAGS -= /O2
    QMAKE_CXXFLAGS_RELEASE -= /O2
    message($$QMAKE_CFLAGS)
    message($$QMAKE_CFLAGS_RELEASE)
    message($$QMAKE_CXXFLAGS)
    message($$QMAKE_CXXFLAGS_RELEASE)
    
    QMAKE_CXXFLAGS += -Od
    

    This prints the following to general messages in Qt Creator, or the terminal when compiling from there:

    Project MESSAGE: Before:
    Project MESSAGE: -nologo -Zc:wchar_t -FS -Zc:strictStrings
    Project MESSAGE: -O2 -MD
    Project MESSAGE: -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -permissive- -Zc:__cplusplus -Zc:externConstexpr
    Project MESSAGE: -O2 -MD
    Project MESSAGE: After:
    Project MESSAGE: -nologo -Zc:wchar_t -FS -Zc:strictStrings
    Project MESSAGE: -MD
    Project MESSAGE: -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -permissive- -Zc:__cplusplus -Zc:externConstexpr -Od
    Project MESSAGE: -MD
    

    So I can see that it's removed -O2 and added in -Od. But when I compile, it's now passing both -O2 and -Od to cl, and producing this error:

    cl : Command line warning D9025 : overriding '/Od' with '/O2'
    

    Is there anything I can do to disable optimizations?

    1 Reply Last reply
    0

    • Login

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