I'm trying to use new C++0x features in Qt Creator under Windows (Qt Creator 2.0.1).
I read the thread Configuring the GCC compiler switches in Qt, Qt Creator, and QMake and added QMAKE_CXXFLAGS += -std=c++0x
to .pro file.
After it Qt Creator gives me very strange errors on this simple code:
#include <memory>
int main()
{
}
Compiler errors:
'::swprintf' has not been declared
'::vswprintf' has not been declared
I try to compile my code from the command line with command g++ test.cpp --std=c++0x
and get same error.
So what's wrong with Qt MinGW compiler? Is it possible to use C++0x features in Qt Creator?
First off, it could be that the library headers just don't represent their dependencies properly. Try adding an #include <cstdio>
and perhaps (unfortunately) a using namespace std;
to your file at the top.
Failing that, several people seem to have had issues with MinGW and swprintf. This mailing list post suggests adding this:
#ifdef WIN32
#define swprintf _snwprintf
#endif
See if that resolves the issue. (You want it at the very top of the file, too.)
If prepending random defines to your source seems like a bad idea to you, I suggest using -D
build flags to conditionally inject the above define when you're building on MinGW.
See also this short discussion on the differences between swprintf on MinGW vs. other compilers.
Finally, failing all else, this link seems to attribute the problem to an issue with flags that enable __STRICT_ANSI__
in MinGW, and suggests commenting out a couple of lines in one of the MinGW headers to fix the issue. I would suggest adding a simpler #ifndef __STRICT_ANSI__
around them instead if you decide to go with this hack.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With