Subject: Re: some warnings when compiling for windows

Re: some warnings when compiling for windows

From: Ivan Pechorin <>
Date: Mon, 31 Oct 2011 10:21:08 -0200

2011/10/31 Daniel Stenberg <>:
> On Mon, 31 Oct 2011, Vincent Torri wrote:
>> warning: #warning Please include winsock2.h before windows.h [-Wcpp]
> Is there an explanation to this somewhere? I know other libraries that don't
> do this as well but still seem to work fine on Windows so I'm a bit
> curious...

The official explanation is here:

"The Winsock2.h header file internally includes core elements from the
Windows.h header file, so there is not usually an #include line for
the Windows.h header file in Winsock applications. If an #include line
is needed for the Windows.h header file, this should be preceded with
the #define WIN32_LEAN_AND_MEAN macro. For historical reasons, the
Windows.h header defaults to including the Winsock.h header file for
Windows Sockets 1.1. The declarations in the Winsock.h header file
will conflict with the declarations in the Winsock2.h header file
required by Windows Sockets 2.0. The WIN32_LEAN_AND_MEAN macro
prevents the Winsock.h from being included by the Windows.h header."

So, as far as I understand, the solution is :
1) either include winsock2.h before windows.h
2) or #define WIN32_LEAN_AND_MEAN, then include windows.h, then
include winsock2.h

Received on 2011-10-31