error C2011: 'sockaddr' : 'struct' type redefinition. see declaration of 'sockaddr'

14,227

Solution 1

If you include winsock.h and winsock2.h make sure that you include winsock2.h first. If the includes are not so obvious you can check cpp files in question if you compile them with /P and walk through the generated preprocessor output file.

Solution 2

Just to describe what problem was... Seems like i shouldnt include udt.h before any winsock headers. That's the fix:

 #ifndef WIN32
   #include <unistd.h>
   #include <cstdlib>
   #include <cstring>
   #include <netdb.h>
   #else
   #define WIN32_LEAN_AND_MEAN
    #include <WinSock2.h>
    #include <WS2tcpip.h>
    #include <Windows.h>
   #endif

   #include <udt.h>
   #include <singleton.h>
   #include <excassert.h>
   #include <SharedUtility.h>

   #ifndef WIN32
   void* recvdata(void*);
   #else
   DWORD WINAPI recvdata(LPVOID);
   #endif
Share:
14,227
Croll
Author by

Croll

Updated on August 06, 2022

Comments

  • Croll
    Croll almost 2 years

    I use Visual Studio 2012 and trying to get static library UDT get to work. Unfortunately, i cannot compile project that links UDT lib to itself, i get 159 strange errors about type or macro redefinitions in windows SDK headers.

    c:\program files\windows kits\8.0\include\shared\ws2def.h(96): warning C4005: 'AF_IPX' : macro redefinition 2> c:\program files\windows kits\8.0\include\um\winsock.h(452) : see previous definition of 'AF_IPX' 2>c:\program files\windows kits\8.0\include\shared\ws2def.h(136): warning C4005: 'AF_MAX' : macro redefinition 2> c:\program files\windows kits\8.0\include\um\winsock.h(471) : see previous definition of 'AF_MAX' 2>c:\program files\windows kits\8.0\include\shared\ws2def.h(173): warning C4005: 'SO_DONTLINGER' : macro redefinition 2> c:\program files\windows kits\8.0\include\um\winsock.h(394) : see previous definition of 'SO_DONTLINGER' 2>c:\program files\windows kits\8.0\include\shared\ws2def.h(217): error C2011: 'sockaddr' : 'struct' type redefinition 2> c:\program files\windows kits\8.0\include\um\winsock.h(477) : see declaration of 'sockaddr'

    Previously removed some code which was defining dllexport/dllimport for each UDT function:

    #define UDT_API // no dllimport/export
    

    I checked that library always use #ifdef to check if file is already included. And this error:

    windows kits\8.0\include\um\ws2tcpip.h(703): error C3861: 'WSASetLastError': identifier not found

    May reason be const keyword in that expression (somewhere inside udt):

    UDT_API int bind(UDTSOCKET u, const struct sockaddr* name, int namelen);
    

    What iam missing?