Winsock redefinition errors [duplicate]
Asked Answered
F

1

10

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
Farrison answered 15/7, 2012 at 21:2 Comment(4)
Could you post a code sample? Also try adding #define WIN32_LEAN_AND_MEANAntechamber
Let's see the #include block from the offending module.Juxtaposition
I dont have any fancy includes, i have these //#include <ws2tcpip.h> #include <windows.h> //#include <wininet.h> i have to include them in few .cpp files.Farrison
See also #1372980Appointment
A
24

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

Antechamber answered 15/7, 2012 at 21:10 Comment(1)
After spending a ton of time trying to solve this issue, your explanation is the one that not only worked but also made complete sense. Thanks!Aloft

© 2022 - 2024 — McMap. All rights reserved.