3

I'm giving c++ a try again after being away for 7 years. I've downloaded the newly released Qt 5.0 sdk for osx, but I can't get a basic c++11 feature compiled using Qt Creator. The following statement:

auto i = 3;

results in a compilation error:

mainwindow.cpp:19: error: ISO C++ forbids declaration of 'i' with no type

I've google around for similar problems and found suggestions to put

QMAKE_CXXFLAGS += -std=c++11
  or
CONFIG += c++11

in the .pro file. Unfortunately without success .The build fails on unrecognized command line options.

I must be doing something wrong. Any suggestions?

Thanks,

Frans

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524

3 Answers3

3

It's looks like Qt Creator for Mac bug. I fixed it using

QMAKE_CXXFLAGS += -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.7
LIBS += -stdlib=libc++ -mmacosx-version-min=10.7

in .pro file

inkooboo
  • 2,904
  • 1
  • 19
  • 24
1

I don't know if this is still an issue for you.

On my current system (Max OS X Yosemite - Qt 5.4 - QtCreator 3.0 - XCode 6.1.1) this works like a charm:

In .pro file:

macx {
    QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7
    QMAKE_CXXFLAGS += -mmacosx-version-min=10.7
    QMAKE_CFLAGS += -mmacosx-version-min=10.7
    QMAKE_MAC_SDK = macosx10.9
}

macx {
    QMAKE_CXXFLAGS += -std=c++11 -stdlib=libc++
    QMAKE_CFLAGS += -std=c++11 -stdlib=libc++
}
CONFIG += c++11

Make sure you have the latest Mac OS X SDK installed too.

RGPaul
  • 401
  • 1
  • 4
  • 11
0

According to the gcc feature list, auto is supported since gcc 4.4through:

g++ -std=c++0x

you could also try the gcc-specific form:

g++ -std=gnu++0x

Maybe, in your case, an additional problem occurs (g++ parameters not correctly promoted to the compiler).

rubber boots
  • 14,924
  • 5
  • 33
  • 44
  • Thanks. No luck unfortunately. I suspect that the problem is related to the way the Qt 5.0 sdk for Mac is build (clang vs. g++). But I don't know enough about the XCode tools and/or Qt to proceed. I didn't find the Qt documentation helpful in this respect. – user1936348 Dec 30 '12 at 22:01