Thread: Strange MSVC winsock2 compile error

  1. #1
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856

    Question Strange MSVC winsock2 compile error

    If you can answer this question I will really appreciate it.. It's making me crazy because there doesn't seem to be any reason for it. I am getting about 100 compile errors all from within winsock2.h... Here are a few:
    c:\program files\devstudio\vc98\include\winsock2.h(99) : error C2011: 'fd_set' : 'struct' type redefinition
    c:\program files\devstudio\vc98\include\winsock2.h(134) : warning C4005: 'FD_SET' : macro redefinition
    c:\program files\devstudio\vc98\include\winsock.h(83) : see previous definition of 'FD_SET'
    c:\program files\devstudio\vc98\include\winsock2.h(143) : error C2011: 'timeval' : 'struct' type redefinition
    c:\program files\devstudio\vc98\include\winsock2.h(199) : error C2011: 'hostent' : 'struct' type redefinition
    c:\program files\devstudio\vc98\include\winsock2.h(212) : error C2011: 'netent' : 'struct' type redefinition
    c:\program files\devstudio\vc98\include\winsock2.h(219) : error C2011: 'servent' : 'struct' type redefinition
    I have searched and searched. It appears that this might happen if you #include both winsock2 and winsock, but winsock.h is not mentioned anywhere in my source. winsock2.h is only #include'd once in all my source..

    Help.. Thanks.

  2. #2
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Thanks vVv. Surprisingly, it appears windows.h is the culprit. I moved my #include above the windows.h #include and the errors ceased.

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Yes, winsock2.h must be included before windows.h. Or, you can #define WIN32_LEAN_AND_MEAN before you include windows.h and it will stop windows.h from including winsock.h.

  4. #4
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Thanks for the insight Eibrow. It's all new to me (windows programming without MFC I mean).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  4. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  5. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM