使用Qt编译winsocket相关代码时报“无法解析的外部符号 …”的错误。
报错内容:
- error LNK2019: 无法解析的外部符号 __imp_connect
- error LNK2019: 无法解析的外部符号 __imp_htons
- error LNK2019: 无法解析的外部符号 __imp_inet_addr
- error LNK2019: 无法解析的外部符号 __imp_send
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e77b42c6ed9974103253926bded00ab4.png)
原因分析:
缺少ws2_32.lib链接。
解决方法
在报错的cpp文件#include下方添加如下代码:
#pragma comment(lib,"ws2_32.lib")