Winsock redefinition errors [duplicate]

不羁的心 提交于 2019-12-06 19:56:57

问题


I am compiling a project in Visual C++ 2010, but I have problems with some Winsock redefinitions.

First of all I get:

syntax error : identifier 'SOCKADDR_STORAGE'

But if I include winsock or winsock2 or ws2tcpip i get many errors like these:

error C2011: 'sockaddr' : 'struct' type redefinition 
error C2011: 'WSAData' : 'struct' type redefinition
error C2011: 'linger' : 'struct' type redefinition

回答1:


Your problem is that by including Windows.h, you are also already including winsock.h. It is here your problem arises as including winsock2.h or ws2tcpip.h will attempt to redefine some of the definitions in winsock.h

By using #define WIN32_LEAN_AND_MEAN before your Windows.h include you stop the compiler from including a lot of the extra stuff that comes with Windows.h



来源:https://stackoverflow.com/questions/11495589/winsock-redefinition-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!