A program I’m working on gives many compilation errors like this:
c:\Program Files\...\PlatformSDK\Include\WinSock2.h(108) :
error C20011: 'fd_set' : 'struct' type redefinition
c:\Program Files\...\PlatformSDK\Include\WinSock.h(54) :
see declaration of 'fd_set'
This occurs when both WinSock.h and WinSock2.h are included and WinSock.h is included before WinSock2.h. Since WinSock2.h guards against WinSock.h by defining _WINSOCKAPI_, including WinSock2.h before WinSock.h is not a problem. windows.h also includes WinSock.h, thus windows.h must come after WinSock2.h.
In my code, all the platform dependent stuff goes into platform.h, in which WinSock2.h is included before windows.h, so what is the problem? It turns out that my code uses OpenSSL and openssl/rand.h includes windows.h. Putting platform.h in front of openssl/rand.h solves the problem.