Thread: winsock2 on wins

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    630

    winsock2 on wins

    Im having problems with compiling my project under MSVC 2005. I included "winsock2.h" only once and linked with "ws2_32.lib" but I get loads of errors (no idea why):

    Code:
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock2.h(112) : error C2011: 'fd_set' : 'struct' type redefinition
            c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock.h(54) : see declaration of 'fd_set'
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock2.h(147) : warning C4005: 'FD_SET' : macro redefinition
            c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock.h(88) : see previous definition of 'FD_SET'
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock2.h(156) : error C2011: 'timeval' : 'struct' type redefinition
            c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock.h(97) : see declaration of 'timeval'
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock2.h(212) : error C2011: 'hostent' : 'struct' type redefinition
            c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock.h(153) : see declaration of 'hostent'
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock2.h(225) : error C2011: 'netent' : 'struct' type redefinition
            c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock.h(166) : see declaration of 'netent'
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock2.h(232) : error C2011: 'servent' : 'struct' type redefinition
            c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock.h(173) : see declaration of 'servent'
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock2.h(244) : error C2011: 'protoent' : 'struct' type redefinition
            c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock.h(185) : see declaration of 'protoent'
    etc..

    What is the cause of this?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you have conflict between winsock and winsock2

    try to move winsock2.h higher ( before other includes)
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    630
    Thanks. That helped.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    In particular, make sure it is always before <windows.h>, or #define WIN32_LEAN_AND_MEAN before including <windows.h>. The macro prevents the header from including winsock, along with a load of other stuff that's rarely needed.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. if statement is evaluating incorrectly ...
    By Niss in forum C Programming
    Replies: 3
    Last Post: 09-12-2008, 04:39 PM
  2. Linker errors on Winsock2 functions
    By ShadowMetis in forum C++ Programming
    Replies: 2
    Last Post: 11-20-2004, 11:19 PM
  3. cant use winsock2 in dev-c++
    By datainjector in forum Tech Board
    Replies: 2
    Last Post: 08-30-2003, 03:55 PM
  4. WINS api?
    By jair in forum Windows Programming
    Replies: 8
    Last Post: 06-28-2003, 08:31 PM
  5. Strange MSVC winsock2 compile error
    By LuckY in forum Windows Programming
    Replies: 3
    Last Post: 06-28-2003, 08:18 AM