I found out how to fix my problem. MinGW already has required libraries (libgdi32.a) and the compiler automatically includes them when the switch '-mwindows' is used.