Resolving conflicts between Winsock.h and Winsock2.h in VS2010 (repeating definition)--Reprint
When these two header files are reversed, there are many confusing errors in the compilation, with the following errors:
1>...\include\ws2def.h: Warning C4005: ' af_ipx ': Macro redefinition
1>...\include\winsock.h (460): See previous definition of ' af_ipx '
...
Or the mistake.
#error "Ws2tcpip.h is not a compatible with winsock.h. Include winsock2.h instead. "
[cause analysis]
The main reason is because the <Windows.h> contains <Winsock.h> header files, because of the different versions, resulting in the above errors. The relevant code in <Windows.h> is as follows:
#ifndef Win32_lean_and_mean
#include <cderr.h>
#include <dde.h>
#include <ddeml.h>
........
#ifndef _mac
#include <winperf.h>
#include <winsock.h>
#endif
.......
#include <commdlg.h>
#endif
#endif
From the above code can be seen if the Win32_lean_and_mean macro is not defined under the premise of Windows.h may contain Winsock.h header file, and we want to use the header file for <winsock2.h> <Winsock.h> and what we need is not a version, so there will be the above error.
[Solutions]
It is easy to add # include <Winsock2.h> to all include statements in the current project (which is the project that is compiled), thus avoiding the error of repeating the header file.
This is the most annoying header file location problem in C + + ... O (︶^︶) o Alas
Resolve Winsock.h and Winsock2.h conflicts in VS2010 (repeat definition)--reprint