简体   繁体   English

如何强制Qt QMake项目使用C ++ 98标准?

[英]How is possible to force Qt QMake project to use C++98 standard?

I tried this in my .pro and it is being ignored: 我在.pro尝试过此方法,但该方法被忽略了:

TEMPLATE = app
CONFIG += console c++98
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += \
        main.cpp

The simplest solution would be to have a cmake project instead. 最简单的解决方案是改为使用cmake项目。 Then you'd have: 然后您将拥有:

# CMakeLists.txt
cmake_minimum_required(VERSION 3.1)

project(foo)
add_executable(${PROJECT_NAME} "main.cpp")
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 98)

Qt Creator supports cmake projects, thus there's no advantage to using qmake for such projects anymore. Qt Creator支持cmake项目,因此不再将qmake用于此类项目。 After all, the Qt dependency is specious - it's a dependency on qmake and nothing else, and qmake only comes bundled with Qt's Base module. 毕竟,Qt依赖性很强-它是对qmake的依赖性,仅此而已,并且qmake仅与Qt的Base模块捆绑在一起。

For qmake, you have to set the compiler flags directly: 对于qmake,必须直接设置编译器标志:

!win32-msvc: QMAKE_CXXFLAGS += -std=c++98

Theres no way to set it for MSVC, no matter what build tool you're using: it's the limitation of the compiler itself. 无论您使用哪种构建工具,都无法为MSVC设置它:这是编译器本身的局限性。 The only approach is to use a sufficiently old toolset, and optionally override QMAKE_CXX with the compiler's name (not path!). 唯一的方法是使用足够旧的工具集,并可以选择使用编译器的名称(而非路径!)覆盖QMAKE_CXX The compiler needs to be in the PATH , ie you'd have to use the toolset's vsvars script to set it up. 编译器必须位于PATH ,即您必须使用工具集的vsvars脚本进行设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM