Important: Please read the Qt Code of Conduct -

[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,
    from c:\development\qt\mingw\bin../lib/gcc/mingw32/4.4.0/include/c++/bits/char_traits.h:42,
    from c:\development\qt\mingw\bin../lib/gcc/mingw32/4.4.0/include/c++/string:42,
    from c:\Development\qt\Desktop\Qt\4.7.3\mingw\include/QtCore/qstring.h:60,
    from c:\Development\qt\Desktop\Qt\4.7.3\mingw\include/QtCore/qobject.h:48,
    from c:\Development\qt\Desktop\Qt\4.7.3\mingw\include/QtCore/qtimer.h:48,
    from c:\Development\qt\Desktop\Qt\4.7.3\mingw\include/QtCore/QTimer:1,
    from ....\project\src\main.cpp:1:
    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": 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:

  • I will, thanks.

    JFYI "this": is a list of C++0x language features supported by the various versions of GCC / MinGW.

Log in to reply