Subject: Re: some warnings when compiling for windows

Re: some warnings when compiling for windows

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

2011/10/31 Daniel Stenberg <daniel_at_haxx.se>:
> 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:
http://msdn.microsoft.com/en-us/library/ms737629(VS.85).aspx

"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

Regards,
Ivan
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2011-10-31