Sunday, September 22, 2013

error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

Had this error when building a Qt program in Visual Studio 2012:
error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
There was a main() in main.cpp, which was included and compiled in the project. So what happened?
Turned out that qtmaind.lib was removed from Linker Dependencies, added it back and problem solved. Don't ask me why I removed it in the first place :)

Here's my general way to solve this particular linker error when playing with Qt in Visual Studio:
  1. Ensure main() is defined in a file (eg: main.cpp).
  2. Ensure the file (eg: main.cpp) is included in the project.
  3. Ensure the file is really being compiled, type some garbage and build. If there are errors in the file then it's being compiled.
  4. Right-click the project and click Properties.
  5. Go to Configuration Properties -> Linker
    1. Go to Input, ensure Additional Dependencies has one of this entry:
      • qtmaind.lib (for Debug build)
      • qtmain.lib (for Release build)
    2. Go to System, ensure SubSystem is correct.
    3. Go to Advanced, ensure Entry Point is correct. The default is blank. Usually you don't mess with it and leave it blank.