OpenSSL and Windows Socket

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.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s