Undefined reference to WinMain@16
I am build Qt on Windows, and install QtCreator.
If I create new project -> C++ Library and compile this project, I see this error @undefined reference to WinMain@16@
@C:/Qt/MinGW/bin/mingw32-make -f Makefile.Release
mingw32-make: Entering directory
C:/Users/Ruslan/Documents/Qt/untitled' g++ -c -O2 -Wall -Wextra -fno-exceptions -fno-rtti -DUNICODE -DQT_LARGEFILE_SUPPORT -DUNTITLED_LIBRARY -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NO_DYNAMIC_CAST -I"c:\Qt\4.8.3\include\QtCore" -I"c:\Qt\4.8.3\include" -I"c:\Qt\4.8.3\include\ActiveQt" -I"release" -I"c:\Qt\4.8.3\mkspecs\win32-g++" -o release\untitled.o untitled.cpp g++ -Wl,-s -o release\libuntitled.a release/untitled.o -L".\lib" -L"c:\Qt\4.8.3\lib" -lQtCore4 mingw32-make: Leaving directoryC:/Users/Ruslan/Documents/Qt/untitled'
c:/qt/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a(main.o): In function
main': C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference toWinMain@16'
collect2: ld returned 1 exit status
mingw32-make: *** [release\libuntitled.a] Error 1
mingw32-make: *** [release] Error 2@
The entry point for Windows GUI applications is WinMain(), not main().
Obviously your application doesn't implement a proper WinMain() function, as described here:
Link your application against "qtmain.lib", if you want to use a classical main() method.
But be aware that then your main() method will be called by a "dummy" WinMain() function implemented in "qtmain.lib", it will NOT be called by the C-Runtime directly. This also means that Qt's code will create the "argc" and "argv" arguments for your main() method itself. You wouldn't have to care about that, if Qt's command-line parser/tokenizer didn't have a rather annoying bug that still remains unfixed, as nobody seems to care...
See here for details:
Hi MuldeR, what he created is a library instead of application. so main or WinMain is not needed.
Yes, this is not application
It is library.
I recompiled Qt and reinstall Mingw. But this problem not solved.
Now I install msvc 2010 and this works
But I want use Mingw, not MSVC
Hmm, if he indeed is compiling a DLL and the linker is complaining about a missing reference to "WinMain@16", it seems the wrong C-Runtime (CRT) is being linked in. The DLL CRT shouldn't have a reference to "WinMain@16" at all. It should have a reference to "DllMain()":http://tinyurl.com/cqwzvxq Might be a configuration error (or a screwed up MinGW).
Yes it seems that it doesn't understand that it in fact should be a library. Is your project file properly setup? It might help if we can see it. For example does it have a template for a lib etc?
@TEMPLATE = lib@
Also it might help if we could look at the generated Makefile for the project if you can share that?
I solved this problem
I am uninstall Mingw 4.6, and download Mingw version 4.4
Then rebuild Qt libs and this work fine
@CONFIG += shared@
to your .pro-file!
qmake seems to be confused if neither -shared nor -static build is specified ...