当前位置:网站首页>【QT】capture.obj:-1: error: LNK2019: 无法解析的外部符号 __imp_htons(解决方法)

【QT】capture.obj:-1: error: LNK2019: 无法解析的外部符号 __imp_htons(解决方法)

2022-07-27 06:04:00 Cappuccino-jay

在用QT进行套接字编程时遇到下面的错误:


1、capture.obj error: LNK2019: 无法解析的外部符号 __imp_htons,该符号在函数 “public: int __cdecl Capture::ipPackageHandle(unsigned char const *,int &)” ([email protected]@@[email protected]) 中被引用
2、capture.obj error: LNK2019: 无法解析的外部符号 __imp_ntohl,该符号在函数 “public: int __cdecl Capture::tcpPackageHandle(unsigned char const *,class QString &,int)” ([email protected]@@[email protected]@[email protected]) 中被引用
3、capture.obj error: LNK2019: 无法解析的外部符号 __imp_ntohs,该符号在函数 “public: int __cdecl Capture::ethernetPackageHandle(unsigned char const *,class QString &)” ([email protected]@@[email protected]@@Z) 中被引用
4、datapackage.obj error: LNK2019: 无法解析的外部符号 htonl,该符号在函数 “public: bool __cdecl DataPackage::getTcpOperationSACK(int,unsigned char &,class QVector &)” ([email protected]@@[email protected]@@@Z) 中被引用
5、datapackage.obj error: LNK2019: 无法解析的外部符号 inet_ntoa,该符号在函数 “public: class QString __cdecl DataPackage::getDesIpAddr(void)” ([email protected]@@[email protected]@XZ) 中被引用
6、datapackage.obj error: LNK2019: 无法解析的外部符号 ntohl,该符号在函数 “public: class QString __cdecl DataPackage::getTcpSequence(void)” ([email protected]@@[email protected]@XZ) 中被引用
7、datapackage.obj error: LNK2019: 无法解析的外部符号 ntohs,该符号在函数 “public: class QString __cdecl DataPackage::getMacType(void)” ([email protected]@@[email protected]@XZ) 中被引用
8、debug\shark.exe error: LNK1120: 7 个无法解析的外部命令


在这里插入图片描述

解决方法如下:

在CPP文件include语句之后加上如下代码:

#pragma comment(lib,"ws2_32.lib")

表示链接的时侯找 ws2_32.lib

然后编译就成功了:
在这里插入图片描述

原网站

版权声明
本文为[Cappuccino-jay]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Cappuccino_jay/article/details/125994439