10

So far I've written all my code in visual studio and now I need to add some UI to it so I'm going to use Qt. So I added every file In my project (except main class) and then tried compiling it using Qt. since I've used some c++0x features I had to add this line to project file :

QMAKE_CXXFLAGS += -std=c++0x

then I tried compiling it. there are only two errors (there may be more but compiler stops on these two)

In file included from d:\qt\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/postypes.h:42,

                 from d:\qt\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/iosfwd:42,

                 from d:\qt\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/ios:39,

                 from d:\qt\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/ostream:40,

                 from ../TranslatorBase/ttObject.h:5,

                 from ../TranslatorBase/ttArray.h:5,

                 from ../TranslatorBase/ttArray.cpp:1:

d:\qt\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cwchar:159: error: '::swprintf' has not been declared

d:\qt\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cwchar:166: error: '::vswprintf' has not been declared

I don't have any idea why there should be such an error. and to make sure I first tried to compile same project using cygwin/gcc using this command :

gcc -std=c++0x TranslatorBase/ttArray.cpp -c -o ttArray.o

there is no error there it compiles even without any warnings. In fact every file in my project compiles without any warnings there.

I'm now using Qt Creator v2.0.1 based on Qt v4.7.0 and it's using mingw/gcc v4.4.0

--edit--

just a new thing I've found, even without my source files (only with Qt generated files) there is still compilation error. it seems there is a problem with the gcc I've got.

@Troubadour Qt generated this command:

g++ -c -std=c++0x -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I'd:/Qt/qt/include/QtCore' -I'd:/Qt/qt/include/QtGui' -I'd:/Qt/qt/include' -I'd:/Qt/qt/include/ActiveQt' -I'debug' -I'.' -I'../TranslatorUI' -I'.' -I'd:/Qt/qt/mkspecs/win32-g++' -o debug/ttArray.o ../TranslatorBase/ttArray.cpp
Ali1S232
  • 3,373
  • 2
  • 27
  • 46
  • What `gcc` build command is `qmake` generating? – Troubadour Jul 14 '11 at 21:02
  • Note that [this question](http://stackoverflow.com/questions/3445312/swprintf-and-vswprintf-not-declared) discusses the same issue so it may be of some use. It may be that you are seeing the exact same thing although you don't explicitly have the `-ansi` option so perhaps not. – Troubadour Jul 14 '11 at 21:31
  • If you use `g++` at the command line instead of `gcc` does it still work? – Troubadour Jul 14 '11 at 21:35
  • @Troubadour: it seems like there was same problem here, it seems when you ask the compiler to compile using c++0x std options it also think compilation is restricted to ansi. so I just did as suggested in [this answer](http://stackoverflow.com/questions/5580921/how-can-i-make-c0x-and-strict-ansi-get-along/5580953#5580953). but I don't know if it breaks any thing else or not. – Ali1S232 Jul 14 '11 at 21:48

2 Answers2

11

as Troubadour suggested, it's a problem with mingw, that when you add -std=c++0x flag to compile options, mingw automatically adds -ansi flag too, so to fix that I added -U__STRICT_ANSI__ flag to compile options. problem fixed.

Ali1S232
  • 3,373
  • 2
  • 27
  • 46
  • -std=gnu++0x doesn't even required undefining __STRICT_ANSI__ – rezna Nov 11 '12 at 19:06
  • @rezna it depends, if you are using unicode types and functions you need (at least when I was writing this answer). -ansi will remove support for functions and classes like wstring, wprintf, wcout and so on... – Ali1S232 Nov 12 '12 at 04:23
  • @rezna that's what the other answer said! – Ali1S232 Nov 12 '12 at 09:35
  • I had the same problem when building `VTK 5.8.0` with `MinGW`. Using that flag worked like charm. – Adri C.S. Apr 19 '13 at 11:25
5

I've met the same problem. Changing -std=c++0x to -std=gnu++0x also fix it.

Juan Mellado
  • 14,973
  • 5
  • 47
  • 54
Benjamin Cao
  • 51
  • 1
  • 1