How can I disable compiler optimizations for a release build?
-
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
-Odcommand 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 += -Odhas no effect whatsoever, which already is odd. If I useQMAKE_CXXFLAGSinstead 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 += -OdThis 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: -MDSo I can see that it's removed
-O2and added in-Od. But when I compile, it's now passing both-O2and-Odtocl, and producing this error:cl : Command line warning D9025 : overriding '/Od' with '/O2'Is there anything I can do to disable optimizations?