My project uses windows.h in which winsock.h is used, and I need to include boost:assio which uses winsock2. So I get many errors that says Winsock.h already included. I can define WIN32_LEAN_AND_MEAN. so that windows.h wouldn't use winsock. The problem is , that I need windows.h to use it, and I just need Asio for asynchronous timers. I don't need its winsock2.h . I tried searching how to disable its winsock2 use, and I found that I could do that by defining BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN before including boost:asio, but I still get the same error.
#include <windows.h>
#define BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN
#include <boost/asio.hpp>
Error
1>c:\program files\boost\boost_1_47\boost\asio\detail\socket_types.hpp(22): fatal error C1189: #error : WinSock.h has already been included
An other workarround I used is to concentrate all asio dependent code in an XXX.hpp file and include it on the top of each windows implementing XXX.cpp file where you use its objects.
this method place the include asio above any other include windows.h and work arround the problem.
Try and change the order or includes. Start with boost/asio.hpp and put windows.h after it.
Usually the writers of any code library solve the compatibility issues but they can do it better if their code is the first to meet the compiler and preprocessor.
There's a similar issue with ACE, including ace/OS.h before anything else solves it.
As Danius (the OP) points out a compile with
fails with this error:
On the other hand
Produces a bunch of noise and sets the windows version # incorrectly
I couldn't find any way around this that didn't leave a bad taste, but this:
Does produce a clean compile.
<EDITORIAL> It shouldn't be that hard </EDITORIAL>
For me, switching the order of includes caused compile errors with another Microsoft include I was using - that was declaring things with "typedef interface".
Since my error was coming from socket_types.h, from these lines:
I put an include of "winsock2.h" before the Windows.h, and then finally the boost/asio.hpp include, and things then compiled happily.