如何使用最新的MinGW将qmake设置为C ++ 14? [英] How to set qmake to C++14 with recent MinGW?
您使用的Qt版本未明确支持您使用的编译器.您可以执行以下任一操作:
-
在项目中同时设置
QMAKE_CXXFLAGS_CXX14
和QMAKE_CXXFLAGS_GNUCXX14
:win32-g ++ {QMAKE_CXXFLAGS_CXX14 = -std = c ++ 14QMAKE_CXXFLAGS_GNUCXX14 = -std = c ++ 14}
-
在Qt安装文件夹中的
mkspecs/win32-g ++/qmake.conf
中编辑上述两个变量的默认值. -
添加一个从
win32-g ++
复制的新mkspec
,以您的编译器为目标,并使用它来构建Qt.然后,使用该Qt的所有项目都将正确运行.C ++ 14支持.
I know there are many duplicates.
This is my Test.pro:
CONFIG += c++14
SOURCES += main.cpp
and my main.cpp:
int main(){}
According to the many duplicates this should give me C++14. However, when I build the project with Qt Creator 4.2.0 with Qt 5.8.0-1 and MinGW gcc 5.3.0-1 installed via the maintenance tool I get
g++ -c -pipe -fno-keep-inline-dllexport -g -std=gnu++1y -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\Test -I. -IC:\Qt\5.8\mingw53_32\include -IC:\Qt\5.8\mingw53_32\include\QtGui -IC:\Qt\5.8\mingw53_32\include\QtANGLE -IC:\Qt\5.8\mingw53_32\include\QtCore -Idebug -IC:\Qt\5.8\mingw53_32\mkspecs\win32-g++ -o debug\main.o ..\Test\main.cpp
which is not the -std=c++14
I expect.
I tried all kinds of tricks from other questions such as
QMAKE_CXXFLAGS_CXX14 = -std=c++14
CONFIG += c++14
QMAKE_CXXFLAGS += -std=c++14
SOURCES += main.cpp
which results in
g++ -c -pipe -fno-keep-inline-dllexport -std=c++14 -g -std=gnu++1y -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\Test -I. -IC:\Qt\5.8\mingw53_32\include -IC:\Qt\5.8\mingw53_32\include\QtGui -IC:\Qt\5.8\mingw53_32\include\QtANGLE -IC:\Qt\5.8\mingw53_32\include\QtCore -Idebug -IC:\Qt\5.8\mingw53_32\mkspecs\win32-g++ -o debug\main.o ..\Test\main.cpp
where the second option overwrites the first, meaning it is still in gnu++1y
-mode or just
QMAKE_CXXFLAGS += -std=c++14
SOURCES += main.cpp
which also results in
g++ -c -pipe -fno-keep-inline-dllexport -std=c++14 -g -std=gnu++11 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\Test -I. -IC:\Qt\5.8\mingw53_32\include -IC:\Qt\5.8\mingw53_32\include\QtGui -IC:\Qt\5.8\mingw53_32\include\QtANGLE -IC:\Qt\5.8\mingw53_32\include\QtCore -Idebug -IC:\Qt\5.8\mingw53_32\mkspecs\win32-g++ -o debug\main.o ..\Test\main.cpp
I deleted the build directory and the Test.pro.user file to force a build from scratch, nothing gave me C++14.
How do I tell qmake to use C++14?
The version of Qt that you're using doesn't explicitly support the compiler you're using. You can do either one of the following:
Set both
QMAKE_CXXFLAGS_CXX14
andQMAKE_CXXFLAGS_GNUCXX14
in your project:win32-g++ { QMAKE_CXXFLAGS_CXX14 = -std=c++14 QMAKE_CXXFLAGS_GNUCXX14 = -std=c++14 }
Edit the default values of those two variables as above, in
mkspecs/win32-g++/qmake.conf
within your Qt installation folder.Add a new
mkspec
copied fromwin32-g++
, targeting your compiler, and build your Qt using it. All the project that use that Qt will then behave correctly w.r.t. C++14 support.
这篇关于如何使用最新的MinGW将qmake设置为C ++ 14?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!