I have a project which was created for MinGW + Qt via cmake.
In CMakeLists.txt I have
add_executable (project-name WIN32 ${MOC_SRCS} ${HEADERS} ${SOURCES} ${RESOURCES} ${QtApp_RCC_SRCS})
If I try to compile it into VisualStudio 2010 I get the following linker error:
MSVCRTD.lib(crtexew.obj) : error LNK2019: undefined reference _WinMain@16 in func ___tmainCRTStartup
Then I erase WIN32
add_executable (project-name ${MOC_SRCS} ${HEADERS} ${SOURCES} ${RESOURCES} ${QtApp_RCC_SRCS})
The project compiles and works fine, but I have an a console window with a Qt window. How to disable the console?
Using
WIN32within add_executable means your application will be of the type SUBSYSTEM:WINDOWS. That is, an application which does not require a console. If this is specified then, rather than amain(...), aWinMain(...)(which has different arguments from a main) is expected. Since your code most likely does not have this, you get the linker error you report.Removing
WIN32means your executable will be of the default type SUBSYSTEM:CONSOLE, which explains why your application works, but a console is shown.So to fix it, do specify
WIN32but change yourmain()to aWinMain().