Resolving conflicts between Winsock.h and Winsock2.h in VS2010 (repeating definition)--Reprint

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.