Click to See Complete Forum and Search --> : Errors C2011 and C2375 when using winsock2.h
isa_jez
March 11th, 2004, 10:59 PM
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"
)
j0nas
March 12th, 2004, 03:33 AM
windows.h is includes winsock.h. You can however do like this:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock.2>
...
Hope it helps,
Jonas
Andreas Masur
March 12th, 2004, 03:48 AM
[Moved thread]
isa_jez
March 12th, 2004, 06:53 PM
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)
j0nas
March 12th, 2004, 08:03 PM
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):
// #define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <windows.h>
isa_jez
March 12th, 2004, 11:45 PM
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...
Andreas Masur
March 13th, 2004, 06:06 AM
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...
muskad202
March 14th, 2004, 05:13 AM
i think that if u include <winsock2.h>, u don't need to include <windows.h>.
Andreas Masur
March 14th, 2004, 06:10 AM
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...
isa_jez
March 14th, 2004, 06:48 PM
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
#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?
isa_jez
March 16th, 2004, 12:50 PM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.