winsock2 on wins

This is a discussion on winsock2 on wins within the Windows Programming forums, part of the Platform Specific Boards category; Im having problems with compiling my project under MSVC 2005. I included "winsock2.h" only once and linked with "ws2_32.lib" but ...

  1. #1
    l2u
    l2u is offline
    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    you have conflict between winsock and winsock2

    try to move winsock2.h higher ( before other includes)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    l2u
    l2u is offline
    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,892
    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, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21