Boost::asio winsock and winsock 2 compatibility issue

后端 未结 5 574
难免孤独
难免孤独 2020-12-28 16:57

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

5条回答
  •  醉话见心
    2020-12-28 17:17

    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:

    # if defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)
    #  error WinSock.h has already been included
    # endif // defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)
    

    I put an include of "winsock2.h" before the Windows.h, and then finally the boost/asio.hpp include, and things then compiled happily.

提交回复
热议问题