View Full Version : How can I use C++11?

12th April 2012, 09:22
Well, actually my question is what do I need to use the latest version of MinGW with Qt Creator (if necessary Qt Creator 2.5 beta)?
I have tried to do it myself but I cannot make it work.
GCC 4.4 is supposed to support some of the new features but I cannot get the compiler to use them too.

12th April 2012, 12:06
What have you tried so far?

12th April 2012, 15:37
I have downloaded the latest version of Mingw and I have created a new tool chain in Qt Creator 2.5 and here I am stuck. I have no idea what to do next?

I have also tried to use this option QMAKE_CXXFLAGS += -std=c++0x in Qt Creator 2.4 with the standard toolchains but it doesn't seem to enable the new language extensions in GCC 4.4 (Mingw).
If I am not mistaken this type of declaration should be supported in GCC 4.4:

auto doSomething(int a) -> int
return a;

but it doesn't work.

Or maybe it is necessary to compile Qt with Mingw 4.6 to be able to use it?

12th April 2012, 17:12
Can you see the "-stc=c++0x" part in the invocation of the compiler while you are building a project?

12th April 2012, 20:45
Yes, I do.

This is the error I get when I use that option. QMAKE_CXXFLAGS += -std=c++0x

21:40:12: Running build steps for project untitled3...
21:40:12: Configuration unchanged, skipping qmake step.
21:40:12: Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
C:/QtSDK/mingw/bin/mingw32-make.exe -f Makefile.Debug
mingw32-make.exe[1]: Entering directory `C:/Users/isto/Documents/QtMobile/untitled3-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug'
g++ -c -std=c++0x -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -I"..\untitled3" -I"." -I"c:\QtSDK\Desktop\Qt\4.8.0\mingw\mkspecs\win32-g++" -o debug\main.o ..\untitled3\main.cpp
In file included from c:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/postypes.h:42,
from c:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/iosfwd:42,
from c:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/ios:39,
from c:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/ostream:40,
from c:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/iostream:40,
from ..\untitled3\main.cpp:1:
c:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cwchar:159: error: '::swprintf' has not been declared
c:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cwchar:166: error: '::vswprintf' has not been declared
mingw32-make.exe[1]: Leaving directory `C:/Users/isto/Documents/QtMobile/untitled3-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug'
mingw32-make.exe[1]: *** [debug/main.o] Error 1
mingw32-make.exe: *** [debug] Error 2
21:40:13: The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project untitled3 (target: Desktop)
When executing build step 'Make'

12th April 2012, 21:33
If i remember correctly MingW 4.4 doesn't implement lambda's, so you need to install a newer version of compiler.
Here (http://gcc.gnu.org/projects/cxx0x.html) is the "0x status" for g++ (i guess the versions should match - in that case you need 4.5 for lambda functions)

13th April 2012, 06:54
It doesn't really matter. If I add QMAKE_CXXFLAGS += -std=c++0x to the .pro file and even if I just have this:

#include <QCoreApplication>

int main(int argc, char *argv[])
QCoreApplication a(argc, argv);

return a.exec();

UPDATE: This thread http://qt-project.org/forums/%20/viewthread/6731 suggest to use -std=gnu++0x instead of -std=c++0x and now the above code compiles without any errors or warnings. That's with the built-in MinGW compiler.

So do I need to compile Qt now to use it with MingGW 4.6?

How long would it take to compile it on a mobile i5 with 3Gb RAM?