qmake: how to override -std=... compiler flag?
-
wrote on 11 Jan 2023, 15:24 last edited by
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). -
wrote on 13 Jan 2023, 21:31 last edited by Violet Giraffe
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. -
wrote on 11 Jan 2023, 15:48 last edited by
you are adding it. Can you simply replace it? Try something like?
QMAKE_CXXFLAGS =-std=c++2b /*more other options if there are more */ -
wrote on 11 Jan 2023, 16:24 last edited by
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
wrote on 11 Jan 2023, 16:28 last edited by JoeCFD 1 Nov 2023, 16:33@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 -
wrote on 11 Jan 2023, 17:46 last edited by
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=
?wrote on 11 Jan 2023, 17:48 last edited by JoeCFD 1 Nov 2023, 17:52@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. -
wrote on 11 Jan 2023, 18:23 last edited by
@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.wrote on 11 Jan 2023, 21:28 last edited by@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 -
Lifetime Qt Championwrote on 11 Jan 2023, 23:46 last edited by Chris Kawa 1 Nov 2023, 23:47
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 wrote on 12 Jan 2023, 12:41 last edited by@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?Lifetime Qt Championwrote on 12 Jan 2023, 13:14 last edited by Chris Kawa 1 Dec 2023, 14:03@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. -
wrote on 12 Jan 2023, 21:08 last edited by Violet Giraffe 1 Dec 2023, 21:08
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).
-
Lifetime Qt Championwrote on 12 Jan 2023, 22:03 last edited by Chris Kawa 1 Dec 2023, 22:10
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.
-
wrote on 12 Jan 2023, 22:31 last edited by
I see, thank you!
-
wrote on 13 Jan 2023, 21:31 last edited by Violet Giraffe
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.wrote on 5 Feb 2023, 14:07 last edited by Violet Giraffe 2 May 2023, 14:07@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!!!