Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Creator compilation error "::swprintf and ::vswprintf has not been declared"

Tags:

c++

gcc

c++11

mingw

qt

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
like image 498
Ali1S232 Avatar asked Jul 14 '11 20:07

Ali1S232


2 Answers

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.

like image 54
Ali1S232 Avatar answered Nov 11 '22 21:11

Ali1S232


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

like image 5
Benjamin Cao Avatar answered Nov 11 '22 23:11

Benjamin Cao