CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2003
    Location
    Trinidad
    Posts
    48

    Errors C2011 and C2375 when using winsock2.h

    Hi,

    When I include a file that has winsock2.h included in it to my project...

    I'm getting errors such as (58 in total):

    c:\Program Files\Microsoft Visual Studio .NET\Vc7
    \PlatformSDK\Include\WinSock2.h(153): error
    C2011: 'timeval' : 'struct' type redefinition

    and

    c:\Program Files\Microsoft Visual Studio .NET\Vc7
    \PlatformSDK\Include\WinSock2.h(1650): error
    C2375: 'closesocket' : redefinition; different linkage


    Could someone tell me what I can do?
    or where the source of the error could be?

    (here's the list ob libraries from my project, if it's of any use

    /OUT:"Debug/demo.exe" /INCREMENTAL /NOLOGO /LIBPATH:
    "c:\wxWindows\lib" /NODEFAULTLIB:"libcd.lib" /NODEFAULTLIB:"lib
    cid.lib" /NODEFAULTLIB:"msvcrt.lib" /DEBUG /PDB:"Debug/full.pdb"
    odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib
    winmm.lib wxmswd.lib zlibd.lib regexd.lib pngd.lib jpegd.lib tiffd.lib
    wxxrcd.lib Wldap32.lib Ws2_32.lib kernel32.lib user32.lib
    gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib
    ole32.lib oleaut32.lib uuid.lib odbc32.lib
    odbccp32.lib "\wxWindows\lib\wxmswd.lib"
    "\wxWindows\lib\zlibd.lib" "\wxWindows\lib\regexd.lib" "\wxWind
    ows\lib\pngd.lib" "\wxWindows\lib\jpegd.lib" "\wxWindows\lib\tiffd
    .lib" "\wxWindows\lib\wxxrcd.lib"

    )

  2. #2
    Join Date
    Aug 2001
    Location
    Stockholm, Sweden
    Posts
    1,664
    windows.h is includes winsock.h. You can however do like this:
    Code:
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <winsock.2>
    ...
    Hope it helps,
    Jonas

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    [Moved thread]

  4. #4
    Join Date
    Dec 2003
    Location
    Trinidad
    Posts
    48

    thanks...but......

    thanks for your reply J0nas...

    I think you're definately right about windows.h and winsock2.h clashing...

    Cause I get the exact same error messages when i tested them out in a single cpp file.

    So here's what's happening
    when i use a single cpp file
    and include windows.h and winsock2.h i get the same errors...
    when i add #define WIN32_LEAN_AND_MEAN
    as you said it's all fixed...

    The problem is tho, when i include:

    #define WIN32_LEAN_AND_MEAN

    before #include <windows.h>

    in my project it doesn't fix the problem....

    what am i doing wrong?

    (i attached a zip file with the project in case you're so kind as to have a look....i would VERY much appreciate it (dealine is April 2nd!) thanks alot for your help...)

    (oh by the way...if you DO look at the project windows.h is included in ldap.h and winsock2.h is included in imapsocket.h)
    Attached Files Attached Files

  5. #5
    Join Date
    Aug 2001
    Location
    Stockholm, Sweden
    Posts
    1,664
    I couldn't build your project becuase some H files were missing... Anyway, I looked into the newer winsock2.h (.net2002 and higher) and it looks like it should work even better if you include winsock2.h before windows.h... Then you can remove the WIN32_LEAN_AND_MEAN thing... Something like this (imapsocket.h):
    Code:
    // #define WIN32_LEAN_AND_MEAN
    #include <winsock2.h>
    #include <windows.h>

  6. #6
    Join Date
    Dec 2003
    Location
    Trinidad
    Posts
    48
    Actually i noticed that too...
    that in winsock2.h they block winsock.h from being included...

    i didn't get the chance to try it out tho...

    You see the thing is tho, that winsock2.h and windows.h aren't included in the same file...so i'm not sure what to do...

    the next thing i'll try is just slipping in winsock2.h just above windows.h...

    so when I try that i'll post here and tell you the result..

    thanks for the help

    P.S.
    Oh, well sorry, i should have told you this...but my project uses wxWindows to implement the GUI

    that's probably what you're missing...

  7. #7
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by isa_jez
    You see the thing is tho, that winsock2.h and windows.h aren't included in the same file...so i'm not sure what to do...
    One thing you can try is to provide a separate header which simply includes 'winsock2.h' before 'windows.h'. Then you include this header instead...

  8. #8
    Join Date
    Jun 2002
    Location
    DUBAI
    Posts
    28
    i think that if u include <winsock2.h>, u don't need to include <windows.h>.

  9. #9
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by muskad202
    i think that if u include <winsock2.h>, u don't need to include <windows.h>.
    Yes...that is true...'winsock2.h' will pull in 'windows.h' if necessary...however, that might not help necessarely...

  10. #10
    Join Date
    Dec 2003
    Location
    Trinidad
    Posts
    48

    to no avail

    well all the solutions work for when the files are included ONLY in a single .h file

    But that isn't the case with my project...

    i tried everything suggested

    i even tried combining the three .h files into a single one (so that I can put
    Code:
    #include <winsock2.h>
    #include <windows.h>
    just as is seen there...but this didn't help in the project

    I'm beginning to think that maybe the clash isn't coming ONLY from windows.h

    But the thing is, without including the file that includes the file that includes winsock2.h i get no errors

    it's only when i include that file

    (#include <imap/imap.h> that i get the problem...)

    I'm really lost at this point....

    any words of advice?

  11. #11
    Join Date
    Dec 2003
    Location
    Trinidad
    Posts
    48

    ok problems solved!

    Thank God, and thank Ms. Radix (that's a lecturer at my university)

    Apparently what was happening is that wx.h from the wxWindows library was including a file which was including a file which was including windows.h

    so i had to sneak in
    #define WIN32_LEAN_AND_MEAN

    before it to block the problem

    thank you guys for all of the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured