I am trying to build a server with no Qt classes using qmake (since it creates Makefiles so well) with MinGW mixed in there.

I am able to build GUIs fine, but this server fails with:

[...]libmingw32.a(main.o):main.c.text+0x104): undefined reference to 'WinMain@16'.
There are thousands of posts on the web about this error, and I think I've tried all the fixes:

  1. Changed int main() to void main()
  2. Since this is a server with no GUI, I added CONFIG += console (same error with or without console)
  3. Added "QT -= gui" to .pro file
  4. Added "LIBS += -lmingw32 -mwindows" to .pro file
  5. Added "QT_CXXFLAGS+=-mwindows" to .pro file
  6. Added "CXXFLAGS += -mwindows"
  7. Added "LIBS += -u _WinMain@16" to .pro file
  8. Reversed library order (I get the same error but from a cygwin library)
  9. Added explicity path to libmingw32.a (although I think it found it)
  10. Added "using namespace std" in the file with my main()
  11. Added these two lines: "int WinMain@16();" and "intWinMain@16() { }"
  12. Added these two lines: "int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmd, int show);" and "int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmd, int show) { return 0; }"
  13. Removed all main() functions
  14. Added "LIBS += -lmingw32 -mwindows"
  15. Added "LIBS += -lgdi32 -lkernel32 -luser32 -lshell32 -lm"
  16. Moved mingw32 libraries to beginning of LIBS


None of these solutions remove the "undefined reference to 'WinMain@16'" error.

Have I left anything off?