如何使用最近的mingw将Qmake设置为C 14

How to set qmake to C++14 with recent MinGW?

本文关键字:设置 Qmake 何使用 最近 mingw      更新时间:2023-10-16

我知道有很多重复。

这是我的test.pro:

CONFIG += c++14
SOURCES += main.cpp

和我的main.cpp:

int main(){}

根据许多重复,这应该给我C 14。但是,当我使用 QT创建者4.2.0 QT 5.8.0-1 Mingw GCC 5.3.0-1 安装时通过维护工具,我得到

g -c -c -pipe -pipe -fno -keep -inline -dllex -dllexport -g -STD = GNU 1y -frtti -wall -wall -wall -Wall -wextra -fexpections -mthreads -mthreads -dunicode -dunicode -dunicode -dqt_qml_debug -dqml_debug -dq_debug -dq_guii _dqt_guii _dqt_ge_guii cor-dqt_needs_qmain -i .. test -i。-ic: qt 5.8 mingw53_32 include -ic: qt 5.8 mingw53_32 include qtgui -ic -ic: qt qt qt 5.8 5.8 mingw53_32-idebug -ic: qt 5.8 mingw53_32 mkspecs win32 -g -o -o debug main.o .. test test main.cpp

这不是我期望的-std=c++14

我尝试了其他问题的各种技巧,例如

QMAKE_CXXFLAGS_CXX14 = -std=c++14
CONFIG += c++14
QMAKE_CXXFLAGS += -std=c++14
SOURCES += main.cpp

导致

g -c -pipe -pipe -fno -keep -inline -dllexport -STD = C 14 -g -STD = GNU 1y -frtti -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 -ic: qt qt qt 5.8 5.8 mingw53_32-idebug -ic: qt 5.8 mingw53_32 mkspecs win32 -g -o -o debug main.o .. test test main.cpp

第二个选项覆盖第一个,这意味着它仍然在gnu++1y -mode中或仅在

QMAKE_CXXFLAGS += -std=c++14
SOURCES += main.cpp

也导致

g -c -c -pipe -pipe -fno -keep -inline -dllexport -STD = C 14 -g -STD = GNU 11 -frtti -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 -ic: qt qt qt 5.8 5.8 mingw53_32-idebug -ic: qt 5.8 mingw53_32 mkspecs win32 -g -o -o debug main.o .. test test main.cpp

我删除了构建目录和test.pro.user文件以从头开始强制构建,没有任何东西给我C 14。

我如何告诉qmake使用C 14?

您使用的QT版本并未明确支持所使用的编译器。您可以做以下一个

  1. set QMAKE_CXXFLAGS_CXX14QMAKE_CXXFLAGS_GNUCXX14在您的项目中:

    win32-g++ {
       QMAKE_CXXFLAGS_CXX14 = -std=c++14
       QMAKE_CXXFLAGS_GNUCXX14 = -std=c++14
    }
    
  2. 在QT安装文件夹中的mkspecs/win32-g++/qmake.conf中编辑这两个变量的默认值。

  3. 添加从win32-g++复制的新mkspec,定位编译器,并使用它构建QT。然后,使用QT的所有项目都将正确地行事W.R.T.C 14支持。