-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"WinSock.h has already been included" #1441
Comments
Hi @apolukhin, socket_types.hpp(24) has following check: # if defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)
# error WinSock.h has already been included
# endif // defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_) and WinSock2.h (part of Windows SDK, installed with Visual Studio 2019 in my case) has #ifndef _WINSOCK2API_
#define _WINSOCK2API_
#define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */ It seems that Asio just checks if winsock.h was included instead of WinSock2.h. Similar check exists in ws2def.h too: #if !defined(_WINSOCK2API_) && defined(_WINSOCKAPI_)
#error Do not include winsock.h and ws2def.h in the same module. Instead include only winsock2.h.
#endif Maybe winsock.h comes to Boost.Stacktrace headers within Windows.h which has following code: #ifndef _MAC
#if defined(_68K_) || defined(_MPPC_)
#define _MAC
#endif
#endif
...
#ifndef WIN32_LEAN_AND_MEAN
...
#ifndef _MAC
#include <winperf.h>
#include <winsock.h>
#endif
...
#endif
Sorry, I misread last |
It looks like there is no way for Asio to solve this issue:
The most of Windows builds I know use #include <windows.h> with something like #ifdef WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#endif in Boost (because it is not just Boost.Stacktrace who includes windows.h) seems to be overkill (though some Boost libraries define |
There's a feature request to Boost.Stacktrace boostorg/stacktrace#155 that look like should go to ASIO:
"""
The order in which you include
stacktrace.hpp
&asio.hpp
can cause a compilation error on Windows.I tested this on MSVC 19.34.31947 with Boost 1.84.0.
For example, this code doesn't compile:
This is the error message:
It compiles fine if you swap the order:
The same code compiles without issue on Linux (tested with gcc 10 on Debian 11).
This isn't really a huge problem as all you have to do to fix it is include
socket_types.hpp
beforestacktrace.hpp
, but the inconsistency is weird when cross-compiling."""
The text was updated successfully, but these errors were encountered: