Qt5对于c++11的支持

Qt5对于c++11的支持

自从qt5发布,就公布了Qt5对c++11的支持,qt上最明显的是能够使用lumda表达式了,在connect信号的时候写一些比较简单的槽函数仍是很方便的。
可是最近在移植qt5到arm的时候发现,Qt5.7的版本连编译的时候都要gcc编译器支持c++11才能经过configurelinux

checking for C++11... 
arm-none-linux-gnueabi-g++ -c -pipe -O2 -g -std=gnu++11 -Wall -W -fPIC  -I. -I../../../mkspecs/linux-arm-gnueabi-g++ -o c++11.o c++11.cpp
cc1plus: error: unrecognized command line option "-std=gnu++11"
Makefile:180: recipe for target 'c++11.o' failed
make: *** [c++11.o] Error 1 C++11 disabled. ERROR: Qt requires a C++11 compiler and yours does not seem to be that. Please upgrade. 

很不幸,笔者用的是飞思卡尔的imx283,属于armv5,官方给的交叉编译工具并不支持c++11。百度搜了下,发现arm9几乎都不支持c++11,因此Qt5.7的移植宣布失败。c++

笔者在以一种万念俱灰的心情抓了半个小时头发以后,不甘心地解压了Qt5.4版本的压缩包(出于对qtquick 2.0 的执着,笔者认为qml可以解决目前全部的问题,嘿嘿这是否是一种信仰)。在配置参数上加上了-no-c++11,配置经过,make经过。web

你可能会以为若是在5.7的版本也加上-no-c++11也能避免对支持c++11的检测的。答案是no,5.7的configure选线没有-no-c++11,只有:svg

-c++std <edition> .. Compile Qt with C++ standard edition (c++11, c++14, c++1z)
                         Default: highest supported

出于对尽可能靠近最新版本的考虑,笔者又下Qt5.6的版本,一样加入了-no-c++11的配置项,结果:函数

NOTICE: The -no-c++11 / --c++-level=c++98 option is deprecated.

 Qt 5.7 will require C++11 support. The options are in effect for this Qt 5.6 build, but you should update your build scripts to remove the option and, if necessary, upgrade your compiler. 

结果很明显的出来了,Qt5.6.1还能用c++98编,Qt5.7就只能用c++11或者更高版本了。工具

-c++std <edition> .. Compile Qt with C++ standard edition (c++98, c++11, c++14, c++1z)
                         Default: highest supported