分类: C/C++
2008-05-15 18:08:35
Solution:
This problem arises because windows.h (at least, that version of it) includes not winsock2.h but winsock.h; sadly when Microsoft wrote winsock2.h they chose neither to change windows.h to include winsock2.h, which replaces winsock.h, nor to include windows.h from winsock2.h and then add the definitions for the new Winsock 2 API methods & structures (this might seem reasonable since Winsock 2 does, strictly speaking, replace Winsock 1, but since the API must be fully backwards-compatible the distinction is somewhat meaningless and there's no real benefit to making winsock2.h standalone).
The fix is thankfully simple: always "#include
However, you must remember that if windows.h has been included by (for example) a higher-level header file that is subsequently including your header file, it's too late - so you must make sure that the higher-level header files respect this convention also.
It is however rarely necessary to modify the header files of libraries or other code modules you are using just because you include their header files, and their header files include windows.h - you can just include winsock2.h before you include the library's header files.
在包含jrtplib有时候我也遇到这个问题,解决方法与之相同。一句话,在#include
问题描述]
在包含了
下错误:
error C2011: 'fd_set' : 'struct' type redefinition
error C2011: 'timeval' : 'struct' type redefinition
....
error C2375: 'accept' : redefinition; different linkage
[原因分析]
主要原因是因为
本的不同,导致出
#ifndef WIN32_LEAN_AND_MEAN
#include
#include
#include
........
#ifndef _MAC
#include
#include
#endif
.......
#include
#endif
#endif
[解决方案]
由以上代码可以看出如果在没有定义WIN32_LEAN_AND_MEAN宏
提下windows.h有可能包含winsock.h 头文件,因此我们得出一个很简单
的解决方法就是在包含
下所示:
#define WIN32_LEAN_AND_MEAN
#include