Is it possible to build QT 6.2.2 with C++20?
-
J.Hilk Moderatorsreplied to Dmitriano on 6 Dec 2021, 07:06 last edited by J.Hilk 12 Jun 2021, 07:06
@Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:
What happens if my app is built with C++20 (
/std:c++20
option) uses QT built withC++17
(/std:c++17
option)?nothing out of the ordinary, should work just fine.
Is there a way (a configuration option) to build QT with
/std:c++20
with MSVC2019 and CLang 12?IIRC you simply pass
-std=c++20
to the make call ?
maybe there's an option in the cmake file to force this too, but I do not know enough about cmake to help here :D -
@Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:
Is it header only?
No, it's not.
Is there a reason why you are asking this? -
@Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:
std::string in QT
There is no std::string in Qt.
std::string (as anything else from std namespace) comes from C++ standard library.
Which C++ standard library you're using depends on the compiler, not Qt. -
@jsulm are you sure? see https://stackoverflow.com/questions/70241529/c17-and-c20-library-compatibility/70241655, for example, most people say that it is different
std::string
s -
@Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:
are you sure?
Yes, I am. Qt does not implement std::string. Or can you point me to its implementation sources in Qt?
"most people say that it is different" - I fail to see that "most" people say that. Most actually tell you same as what I do.
From my own experience I can tell that there is no problem using a newer C++ standatd in a Qt application than the one used to build Qt. -
@J-Hilk said in Is it possible to build QT 6.2.2 with C++20?:
IIRC you simply pass
-std=c++20
to the make call ?
maybe there's an option in the cmake file to force this too, but I do not know enough about cmake to help here :DThis can indeed be done:
set_property(TARGET tgt PROPERTY CXX_STANDARD 20)
, according to the cmake documentation. This works for individual targets. You can set it "project-wide" by usingset (CMAKE_CXX_STANDARD 20)
. -
@jsulm It is irrelevant where are the sources, it is about ABI compatibility between C++17 and C++20 runtime libs, but you are right about what people say, I misunderstood some answers on stackoverflow.com.
-
right, I need more coffee
-
With MSVC not all versions work together. You cannot (always) link VS2013 code with VS2019 code, though you can link VS2017 and VS2019 code. The selected version of the standard normally does not impact compatibility.
Unfortunately, this is actually a reasonable question to ask: GCC once broke ABI compatibility for std::string when introducing C++11. There is a define in that case to compile C++11 against the old ABI. I don't know of any case with MSVC where this was a problem.
Also, this question is quite relevant IMHO in the context of Qt. When we ported our software from wxWidgets to Qt we had a lot of trouble with QString::toStdString() with MSVC. Something wasn't linked properly such that our software always crashed when std::string's destructor was called. We haven't figured it out, but switched over to using QString::toUtf8().data() instead, which honestly is a better solution as this way the encoding is known.
@Dmitriano that is indeed a good and valid question. But, you don't have to fear anything mixing C++17 and C++20 code with MSVC.
-
@Dmitriano There is
-c++std c++20
configuration parameter, but it is not clear does it work correctly with android builds, because there is still-DCMAKE_CXX_STANDARD=17
in configuration log.
-
@Dmitriano I am not sure what does it exactly mean but
Regarding CMAKE_CXX_STANDARD=17, that's only used for the architecture extraction compile project
, see https://bugreports.qt.io/browse/QTBUG-99108
12/16