[asio] header order dependence with <windows.h>

Hello Christopher, I've used review version of asio and found that if I include <windows.h> header before any asio headers then there are >100 errors arised with symbols redifinition. If it is included after asio headers - it compiles perfectly. Is this problem resolved in current CVS? I've used VC7.1 with last SP on WinXP. The example was accept_timeout.cpp asio example with corresponding header included before and after asio headers. Best, Oleg Abrosimov

Олег Абросимов wrote:
I've used review version of asio and found that if I include <windows.h> header before any asio headers then there are >100 errors arised with symbols redifinition. If it is included after asio headers - it compiles perfectly. Is this problem resolved in current CVS?
This is a problem inherent with <windows.h> in that it includes <winsock.h> if <winsock2.h> has not already been included. ASIO relies on Winsock2 functions, so it needs to include <winsock2.h> before <windows.h>. <winsock2.h> is incompatible with <winsock.h> - once one is included, including the other would lead to errors (but actually, they block on each other's header guards). Since anything that happens before including ASIO headers is out of ASIO's control, I don't think it is even possible for ASIO to solve this problem. The problem is in the broken design (or rather evolution) of the WinAPI includes. Sebastian Redl

Sebastian Redl wrote:
Олег Абросимов wrote:
I've used review version of asio and found that if I include <windows.h> header before any asio headers then there are >100 errors arised with symbols redifinition. If it is included after asio headers - it compiles perfectly. Is this problem resolved in current CVS?
This is a problem inherent with <windows.h> in that it includes <winsock.h> if <winsock2.h> has not already been included. ASIO relies on Winsock2 functions, so it needs to include <winsock2.h> before <windows.h>. <winsock2.h> is incompatible with <winsock.h> - once one is included, including the other would lead to errors (but actually, they block on each other's header guards).
Yes, and to solve it I strongly suggest that you define WIN32_LEAN_AND_MEAN as a global define for all you translation units. It removes most of the junk inside windows.h, including winsock.h, as far as I remember.

On Sun, 17 Dec 2006 21:50:09 +0200, "Yuval Ronen" <ronen_yuval@yahoo.com> said:
Yes, and to solve it I strongly suggest that you define WIN32_LEAN_AND_MEAN as a global define for all you translation units. It removes most of the junk inside windows.h, including winsock.h, as far as I remember.
Yes, that is a good idea. The Windows projects that I work on also use precompiled headers to ensure things are included in the right order. Cheers, Chris
participants (4)
-
Christopher Kohlhoff
-
Sebastian Redl
-
Yuval Ronen
-
Олег Абросимов