winsock2.h中有59个错误 [英] 59 errors in winsock2.h

查看:96
本文介绍了winsock2.h中有59个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用VC ++ 6.0(我不想因为我自己的原因而改变它)而且我正在使用简单的客户端服务器编程winsock2.h。



问题是当我包含winsock2.h并编译它时VC ++有59个错误。

这样的错误:

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):警告C4005:''FD_SET'':宏重新定义

c:\program files \ microsoft visual studio\vc98\include\winsock.h(83):参见''FD_SET'的先前定义'

c:\ programprote files \ microsoft visual studio \vc98\include\winsock2.h(143):错误C2011:''timeval'':''struct''类型重新定义

c:\program files \ microsoft visual studio\vc98\include\winsock2.h(199):错误C2011:''hostent'':''struct''类型重新定义

c :\program files \ microsoft visual studio\vc98\include\winsock2.h(212):错误C2011:''netent'':''struct''类型重新定义

c: \program files\microsoft visual studio \vc98\include\winsock2.h(219):错误C2011:''servent'':''struct''类型重新定义

c:\\ \\ program Files \ microsoft visual studio\vc98\include\winsock2.h(226):错误C2011:''protoent'':''struct''类型重新定义

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):er ror C2011:''sockaddr_in'':''struct''类型重新定义

c:\program files \ microsoft visual studio\vc98\include\winsock2.h(378):错误C2011:''WSAData'':''struct''类型重新定义

c:\ program Files \ microsoft visual studio\vc98\include\winsock2.h(430):警告C4005 :''SO_DONTLINGER'':宏重新定义

c:\program files \ microsoft visual studio\vc98\include\winsock.h(391):参见先前对''SO_DONTLINGER'的定义'

c:\program files \ microsoft visual studio\vc98\include\winsock2.h(483):警告C4005:''AF_IPX'':宏重新定义

c:\program files \ microsoft visual studio\vc98\include\winsock.h(449):查看''AF_IPX'的先前定义'

c:\ program program \微软视觉工作室\vc98 \ include \ winsock2.h(506):警告C4005:''AF_MAX'':宏重新定义



为什么会这样?什么解决了我的问题??

Hi all,
I''m using VC++ 6.0 (and I don''t want to change it becuase of my own reasons) and I''m programming a simple client-server using winsock2.h.

The problem is when I include winsock2.h and compile it the VC++ have 59 errors.
such these 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

Why this happens?? what the solution of my problem??

推荐答案

如果你仔细一点,你会注意到编译器告诉你看到xxxx的先前定义,在winsock.h中找到。换句话说,在某些地方你包括winsock.h。摆脱那个包括,应该修复这些错误。



希望这不会引入一堆新的错误:)。如果在删除 include< winsock.h> 后确实遇到问题,修复它的方法是在stdafx.h中包含以下内容:

If you look a little closer, you will notice the compiler is telling you to "see previous definition of xxxx", which is found in winsock.h. In other words, somewhere you are including winsock.h. Get rid of that include and that should fix these errors.

Hopefully that will not introduce a bunch of new errors :). If you do have problems after deleting include <winsock.h>, the way to fix it is to have the following in your stdafx.h:
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>



请参阅 [ ^ ] MSDN文章。


Refer to this[^] MSDN article.

来自MSDN的文章:

Winsock2.h头er文件内部包含Windows.h头文件中的核心元素,因此Winsock应用程序中的Windows.h头文件通常没有#include行。如果Windows.h头文件需要#include行,则应在#define WIN32_LEAN_AND_MEAN宏之前添加#include行。由于历史原因,Windows.h标头默认包含Windows套接字1.1的Winsock.h头文件。 Winsock.h头文件中的声明将与Windows Sockets 2.0所需的Winsock2.h头文件中的声明冲突。 WIN32_LEAN_AND_MEAN宏阻止Winsock.h被Windows.h标题包含。

The Winsock2.h header file internally includes core elements from the Windows.h header file, so there is not usually an #include line for the Windows.h header file in Winsock applications. If an #include line is needed for the Windows.h header file, this should be preceded with the #define WIN32_LEAN_AND_MEAN macro. For historical reasons, the Windows.h header defaults to including the Winsock.h header file for Windows Sockets 1.1. The declarations in the Winsock.h header file will conflict with the declarations in the Winsock2.h header file required by Windows Sockets 2.0. The WIN32_LEAN_AND_MEAN macro prevents the Winsock.h from being included by the Windows.h header.



Soren Madsen


Soren Madsen


这篇关于winsock2.h中有59个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆