刚在mac mini上安装Qt4.8.4
qmake和clang3.2好不容易装上去后
却发现clang3.2不支援C++11
clang3.2的binary
http://llvm.org/releases/download.html
下载之后直接解压缩
.pro file
#-------------------------------------------------
#
# Project created by QtCreator 2013-02-06T07:23:32
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test00
TEMPLATE = app
CONFIG += -std=gnu++11
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
程式
#include <functional>
#include <iostream>
#include <memory>
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
auto A = 444; //警告,
std::cout<<A<<std::endl;
std::unique_ptr<int> B; //错误讯息
return a.exec();
}
警告 :
auto' type specifier is a C++11 extension [-Wc++11-extensions]
错误讯息 :
error: expected '(' for function-style cast or type construction
std::unique_ptr<int> B
我在QtCreator设置的编译器,该执行档的名称是"clang"
------解决方案--------------------
Clang 3.2 supports most of the language features added in the latest ISO C++ standard,C++ 2011. Use -std=c++11 or -std=gnu++11 to enable support for these features.
需要添加编译选项 -std=c++11 或 -std=gnu++11
------解决方案--------------------
mac os里面默认自带的gcc版本较低
建议还是升级下
参见下面这篇文章
http://stackoverflow.com/questions/13958197/c11-on-mac-with-clang-or-gcc
和
http://stackoverflow.com/questions/13351032/clangs-support-of-c-11-lambda/13364165#13364165
------解决方案--------------------
试试qmake,make看看编译期的参数和你设置的是否一致