Advertisement

winsock2 in vc++

Started by July 18, 2002 11:06 PM
6 comments, last by tHiSiSbOb 22 years, 6 months ago
When I include the winsock2 header in my msvc++ compiler and try to compile my code it gives my many errors talkin about re-definitions. If i do not include it the code compiles. What do i do to include the header so i can use winsock. "Computers are only as smart as their programers" My Site-> Still working on it.
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
What else are ou including and/or what are the redifinition errors (ie. what types).
Advertisement
Other than that i am only including windows.h,stdio.hm ddraw.h and a header that I made for ddraw. I will give you some of the errors.


C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(99) : error C2011: ''fd_set'' : ''struct'' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(134) : warning C4005: ''FD_SET'' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(83) : see previous definition of ''FD_SET''
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(143) : error C2011: ''timeval'' : ''struct'' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(199) : error C2011: ''hostent'' : ''struct'' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(212) : error C2011: ''netent'' : ''struct'' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(219) : error C2011: ''servent'' : ''struct'' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(226) : error C2011: ''protoent'' : ''struct'' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(310) : error C2011: ''in_addr'' : ''struct'' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(368) : error C2011: ''sockaddr_in'' : ''struct'' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(378) : error C2011: ''WSAData'' : ''struct'' type redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(430) : warning C4005: ''SO_DONTLINGER'' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(391) : see previous definition of ''SO_DONTLINGER''
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(483) : warning C4005: ''AF_IPX'' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(449) : see previous definition of ''AF_IPX''
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock2.h(506) : warning C4005: ''AF_MAX'' : macro redefinition
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\winsock.h(468) : see previous definition of ''AF_MAX''


"Computers are only as smart as their programers"
My Site-> Still working on it.
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
You are probably including windows.h, which includes winsock.h by default. (winsock, not winsock2)

Do one of two things:
#define WIN32_LEAN_AND_MEAN
prior to including windows.h.

Or try including winsock2.h before you include windows.h.

One of those will fix it.


[edited by - fingh on July 19, 2002 2:07:36 PM]
Ok that worked thank you. But now i get more errors. dealing with usresolved externals.

code.obj : error LNK2001: unresolved external symbol __imp__socket@12
code.obj : error LNK2001: unresolved external symbol __imp__connect@12
code.obj : error LNK2001: unresolved external symbol __imp__inet_addr@4
code.obj : error LNK2001: unresolved external symbol __imp__htons@4
code.obj : error LNK2001: unresolved external symbol __imp__WSACleanup@0
code.obj : error LNK2001: unresolved external symbol __imp__WSAStartup@8
code.obj : error LNK2001: unresolved external symbol __imp__WSAAsyncSelect@16
.\Debug/spriteanimate.exe : fatal error LNK1120: 7 unresolved externals
Error executing link.exe.

spriteanimate.exe - 8 error(s), 0 warning(s)



what do I do about this.

"Computers are only as smart as their programers"
My Site-> Still working on it.
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
You need to include the Winsock library file..

Do this in your code:
#pragma comment(lib, "ws2_32.lib")

Or just use the project settings "Link" tab to include a ref.

-Nate
"Always forgive your enemies, nothing annoys them more.."
Advertisement
Also i was just reading this in my book last night that before you include window.h do this

#define _WINSOCKAPI_

or something like that ....at work now.

I''m not sure if that is included in the #deinfe WIN32_LEAN_AND_MEAN

It would be included in winsock2.h so if you include that before windows.h it should be right

This topic is closed to new replies.

Advertisement