C ++ 0x with Qt Creator

I am trying to use the new C ++ 0x features in Qt Creator under Windows (Qt Creator 2.0.1).

I read the thread Configuring the GCC Compiler in Qt, Qt Creator, and QMake and added QMAKE_CXXFLAGS += -std=c++0x to the .pro file.

After that, Qt Creator gives me very strange errors in this simple code:

 #include <memory> int main() { } 

Compiler Errors:

':: swprintf' not declared

':: vswprintf' not declared

I am trying to compile my code from the command line with g++ test.cpp --std=c++0x command and get the same error.

So what about the Qt MinGW compiler? Is it possible to use C ++ 0x functions in Qt Creator?

+13
c ++ c ++ 11 qt mingw qt-creator
Feb 15 '11 at 12:18
source share
1 answer

First, it is possible that library headers simply do not represent their dependencies properly. Try adding #include <cstdio> and possibly (unfortunately) a using namespace std; to your file at the top.

Otherwise, a few people have problems with MinGW and swprintf. This mailing list suggests adding the following:

 #ifdef WIN32 #define swprintf _snwprintf #endif 

See if this fixes the problem. (You also want it at the very top of the file.)

If adding random definitions to your source seems like a bad idea, I suggest using the -D build flags to conditionally enter the above definition when you build on MinGW.

See also this short discussion about the differences between swprintf on MinGW and other compilers.

Finally, otherwise, this link seems to attribute the problem to the problem with flags that allow __STRICT_ANSI__ in MinGW, and suggests commenting out a couple of lines in one of the MinGW headers to fix this problem. I would suggest adding a simpler #ifndef __STRICT_ANSI__ , if you decide to go with this hack.

+3
Feb 15 '11 at 12:46
source share
โ€” -



All Articles