c:\program files (x86)\windows kits\8.1\include\um\winsock2.h错误
开发环境:
Windows 10
IDE: VS2013
在一个项目中要调试两个开源库,涉及到TCP通信,开源库使用到了Windows自带的 Winsock.h
而另一个库又include <winsock2.h>,在编译过程中定位问题点花了大半天的时间,新建了几个项目才确定的问题。
记录下解决方案,避免更多朋友踩坑
1>c:\program files (x86)\windows kits\8.1\include\um\winsock2.h(2295): error C2375: “getservbyport”: 重定义;不同的链接
1> c:\program files (x86)\windows kits\8.1\include\um\winsock.h(853): note: 参见“getservbyport”的声明
产生了50个编译错误。
解决方案一: 添加预编译头
项目属性 ——> C/C++ ———> 预处理器 -------> 预处理器定义
增加如下定义
WIN32_LEAN_AND_MEAN
解决方案二:
在编译不过的头文件前面增加
#include <Winsock2.h>
特别是用到了<windows.h>
[原因分析]
主要原因是因为<Windows.h>中包含了<Winsock.h>头文件,由于其版本的不同