Wednesday, January 19, 2011

cygwin gcc undefined reference to `_WinMain@16'

I tried to write a simple HelloWorld.c program using cygwin gcc on a Windows XP machine and got this error: undefined reference to `_WinMain@16'

I am not trying to write any Windows GUI app and this error was surprising for a simple c program. Turns out I need to add a default method as mentioned here. I will try to find a better solution than this, but for now this will do ;)

So here is the final code now.

#include <stdio.h>

static int main();

int __declspec(nothrow) __stdcall WinMain(int a, int b, char* c, int d){

  main();

  return 0;

}

static int main(){

  printf("Hello C Again\n");

  return 0;

}