[Solved] -std=c++0x causes compilation error
I am currently working on a project which should make use of some C++0x features. For this purpose I've added
QMAKE_CXXFLAGS += -std=c++0x
to the project file which - occasionally - leads to the following compiler error
g++ -c -std=c++0x -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_SQL_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"c:\Development\qt\Desktop\Qt\4.7.3\mingw\include\QtCore" -I"c:\Development\qt\Desktop\Qt\4.7.3\mingw\include\QtNetwork" -I"c:\Development\qt\Desktop\Qt\4.7.3\mingw\include\QtGui" -I"c:\Development\qt\Desktop\Qt\4.7.3\mingw\include\QtSql" -I"c:\Development\qt\Desktop\Qt\4.7.3\mingw\include" -I"....\qx\include" -I"c:\Development\qt\Desktop\Qt\4.7.3\mingw\include\ActiveQt" -I"debug" -I"....\project\src" -I"." -I"c:\Development\qt\Desktop\Qt\4.7.3\mingw\mkspecs\win32-g++" -o debug\main.o ....\project\src\main.cpp
In file included from c:\development\qt\mingw\bin../lib/gcc/mingw32/4.4.0/include/c++/bits/postypes.h:42,
c:\development\qt\mingw\bin../lib/gcc/mingw32/4.4.0/include/c++/cwchar:159: error: '::swprintf' has not been declared
c:\development\qt\mingw\bin../lib/gcc/mingw32/4.4.0/include/c++/cwchar:166: error: '::vswprintf' has not been declared
The strange thing is, that commenting out the QMAKE_CXXFLAGS, compiling the project, commenting back in the QMAKE_CXXFLAGS and compiling the project again solves the problem - at least for a while. After doing a few changes to the source files the problem rises again.
Is anyone else already creating C++0x projects and has experienced the same problem?
Looks like it's a bug in MinGW (see also "here":http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40278). You can try to use -std=gnu++0x instead.
Works like a charm so far - even though I've just realised that 4.4's support of C++0x is... moderate. Thanks!
Newest MinGW available is 4.5.2, you might want to try it. That requires you to compile your own Qt, but Qt benefits from c++0x compilation too, according this: http://labs.qt.nokia.com/2011/05/26/cpp0x-in-qt/
I will, thanks.
JFYI "this":http://gcc.gnu.org/projects/cxx0x.html is a list of C++0x language features supported by the various versions of GCC / MinGW.