qmake: how to override -std=... compiler flag?
-
How to override the -std=... flag in a qmake project? If I specify
QMAKE_CXXFLAGS+=-std=c++2b
my flag is added before the default level, and it has to come after to take effect:
g++ -c -pipe -std=c++2b -O3 -fPIC -std=c++2a
c++2a is from CONFIG += c++2a, is there a way to tell qmake not to specify any-std=
value?
CONFIG += c++2b is not an option, Qt 5.15 doesn't know c++2b, and it doesn't accept values that it doesn't know (a stupid design, I think, but that's beside the point). -
i accidentally found a very funny workaround: I spelled
c++_latest
, which is a mistake because the underscore shouldn't be there, and voila - qmake did not add any-std=
option at all! So I was free to then add my covetedc++2b
. I have not tested whether this works with Qt 6, though. -
I've tried this, no change. Or is
-=
not supposed to work here?QMAKE_CXXFLAGS -= -std=c++2a QMAKE_CXXFLAGS += -std=c++2b
-
I've tried this, no change. Or is
-=
not supposed to work here?QMAKE_CXXFLAGS -= -std=c++2a QMAKE_CXXFLAGS += -std=c++2b
@Violet-Giraffe you are right. It will not help. I was wrong.
https://stackoverflow.com/questions/36650216/how-to-remove-alter-default-cflags-in-qmake
there are also debug ones.
https://doc.qt.io/qt-6/qmake-variable-reference.html -
Thanks! But should -= work with
QMAKE_CXXFLAGS_RELEASE
? Because for me it made no difference either (+= works, though). Do I have to reset everything with=
? -
Thanks! But should -= work with
QMAKE_CXXFLAGS_RELEASE
? Because for me it made no difference either (+= works, though). Do I have to reset everything with=
?@Violet-Giraffe As you tried. -= was done earlier. but c++2a was added later. -= does not help.
From the last post in the link QMAKE_CXXFLAGS_RELEASE has only =. I guess you simply add what you need there. -
@JoeCFD said in qmake: how to override -std=... compiler flag?:
Thanks, but that doesn't work either, unfortunately. It made no difference to the command line at all. -
@JoeCFD said in qmake: how to override -std=... compiler flag?:
Thanks, but that doesn't work either, unfortunately. It made no difference to the command line at all.@Violet-Giraffe Just tested it. True no help. You may take a look at the source code of qmake
https://github.com/qt/qtbase/tree/dev/qmake -
These are the values for the standard versions I get on GCC (MinGW 11.2). Not passing any compiler specific flags to QMAKE_CXXFLAGS.
CONFIG switch Compiler flag CONFIG += c++17 -std=gnu++1z CONFIG += c++20 -std=gnu++2a CONFIG += c++latest -std=gnu++2b CONFIG += c++17 strict_c++ -std=c++1z CONFIG += c++20 strict_c++ -std=c++2a CONFIG += c++latest strict_c++ -std=c++2b -
These are the values for the standard versions I get on GCC (MinGW 11.2). Not passing any compiler specific flags to QMAKE_CXXFLAGS.
CONFIG switch Compiler flag CONFIG += c++17 -std=gnu++1z CONFIG += c++20 -std=gnu++2a CONFIG += c++latest -std=gnu++2b CONFIG += c++17 strict_c++ -std=c++1z CONFIG += c++20 strict_c++ -std=c++2a CONFIG += c++latest strict_c++ -std=c++2b @Chris-Kawa, thanks, but unfortunately that's not a good solution - for Qt 5.15 c++latest is still c++2a. Yes, I could switch to Qt 6 just to get this working, but I don't want to do that right now.
This problem comes up every single time there is a new level of C++ support in GCC / clang that needs to be enabled. Is there really no solution, no variable in the qmake project that I can manipulate to get this to work? -
@Chris-Kawa, thanks, but unfortunately that's not a good solution - for Qt 5.15 c++latest is still c++2a. Yes, I could switch to Qt 6 just to get this working, but I don't want to do that right now.
This problem comes up every single time there is a new level of C++ support in GCC / clang that needs to be enabled. Is there really no solution, no variable in the qmake project that I can manipulate to get this to work?@Violet-Giraffe Right. Well, the CONFIG page for Qt5 says it should support c++2b, but when I tried it with 5.15.2 it doesn't add anything, so that's a bummer.
I added
-std=c++2b
directly in the mkspec config and that works ok, but it seems the project using Qt 5.15.2 doesn't compile with C++2b. A bunch of compilation errors occur within Qt's headers . I wonder it that's something that is fixed down the 5.15.x line or Qt5 simply doesn't work with C++2b and that's the reason it's not exposed in qmake. -
That's odd, I don't understand why it would give you errors, will try. It's not a real solution, though, it's a hack, because it requires modifying the Qt installation. Not something I look forward to in CI scripts (e. g. Github Actions).
-
I use warnings as errors, so a long list of them are really just warnings, like deprecated bitwise operations between different enums, but there are also hard errors, e.g. in QtConcurrent around some templated constructors. Maybe related to some CTAD changes that are introduced in C++23, but I haven't investigated further.
EDIT: Yeah, it's this one: QTBUG-91909. Fixed in later versions but not the current open source 5.15.2 available through installer. There's probably more like that.
-
I see, thank you!
-
i accidentally found a very funny workaround: I spelled
c++_latest
, which is a mistake because the underscore shouldn't be there, and voila - qmake did not add any-std=
option at all! So I was free to then add my covetedc++2b
. I have not tested whether this works with Qt 6, though. -
i accidentally found a very funny workaround: I spelled
c++_latest
, which is a mistake because the underscore shouldn't be there, and voila - qmake did not add any-std=
option at all! So I was free to then add my covetedc++2b
. I have not tested whether this works with Qt 6, though.@Violet-Giraffe said in qmake: how to override -std=... compiler flag?:
i accidentally found a very funny workaround: I spelled
c++_latest
, which is a mistake because the underscore shouldn't be there, and voila - qmake did not add any-std=
option at all! So I was free to then add my covetedc++2b
. I have not tested whether this works with Qt 6, though.This doesn't work on Mac, only on Linux. On Mac qmake still inserts
-std=c++11
after my own flags. Argh!!!