环境:Win10-x64+VS2015+Qt5.9.7
使用QT中的QtNetwork模块时,如包含TCP相关头文件:
#include
#include
程序报如下错误:
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 LNK2019 无法解析的外部符号 "__declspec(dllimport) public: virtual __cdecl QTcpSocket::~QTcpSocket(void)" (__imp_??1QTcpSocket@@UEAA@XZ),该符号在函数 "public: virtual void * __cdecl QTcpSocket::`scalar deleting destructor'(unsigned int)" (??_GQTcpSocket@@UEAAPEAXI@Z) 中被引用 SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2019 无法解析的外部符号 "__declspec(dllimport) public: __cdecl QTcpSocket::QTcpSocket(class QObject *)" (__imp_??0QTcpSocket@@QEAA@PEAVQObject@@@Z),该符号在函数 "private: void __cdecl SocketTCPClient::on_m_connectServerBtn_clicked(void)" (?on_m_connectServerBtn_clicked@SocketTCPClient@@AEAAXXZ) 中被引用 SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual bool __cdecl QAbstractSocket::atEnd(void)const " (?atEnd@QAbstractSocket@@UEBA_NXZ) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual __int64 __cdecl QAbstractSocket::bytesAvailable(void)const " (?bytesAvailable@QAbstractSocket@@UEBA_JXZ) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual __int64 __cdecl QAbstractSocket::bytesToWrite(void)const " (?bytesToWrite@QAbstractSocket@@UEBA_JXZ) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual bool __cdecl QAbstractSocket::canReadLine(void)const " (?canReadLine@QAbstractSocket@@UEBA_NXZ) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual void __cdecl QAbstractSocket::close(void)" (?close@QAbstractSocket@@UEAAXXZ) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual void __cdecl QAbstractSocket::connectToHost(class QHostAddress const &,unsigned short,class QFlags)" (?connectToHost@QAbstractSocket@@UEAAXAEBVQHostAddress@@GV?$QFlags@W4OpenModeFlag@QIODevice@@@@@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual void __cdecl QAbstractSocket::connectToHost(class QString const &,unsigned short,class QFlags,enum QAbstractSocket::NetworkLayerProtocol)" (?connectToHost@QAbstractSocket@@UEAAXAEBVQString@@GV?$QFlags@W4OpenModeFlag@QIODevice@@@@W4NetworkLayerProtocol@1@@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual void __cdecl QAbstractSocket::disconnectFromHost(void)" (?disconnectFromHost@QAbstractSocket@@UEAAXXZ) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual bool __cdecl QAbstractSocket::isSequential(void)const " (?isSequential@QAbstractSocket@@UEBA_NXZ) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual struct QMetaObject const * __cdecl QTcpSocket::metaObject(void)const " (?metaObject@QTcpSocket@@UEBAPEBUQMetaObject@@XZ) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual int __cdecl QTcpSocket::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@QTcpSocket@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual void * __cdecl QTcpSocket::qt_metacast(char const *)" (?qt_metacast@QTcpSocket@@UEAAPEAXPEBD@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "protected: virtual __int64 __cdecl QAbstractSocket::readData(char *,__int64)" (?readData@QAbstractSocket@@MEAA_JPEAD_J@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "protected: virtual __int64 __cdecl QAbstractSocket::readLineData(char *,__int64)" (?readLineData@QAbstractSocket@@MEAA_JPEAD_J@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual void __cdecl QAbstractSocket::resume(void)" (?resume@QAbstractSocket@@UEAAXXZ) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual void __cdecl QAbstractSocket::setReadBufferSize(__int64)" (?setReadBufferSize@QAbstractSocket@@UEAAX_J@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual bool __cdecl QAbstractSocket::setSocketDescriptor(__int64,enum QAbstractSocket::SocketState,class QFlags)" (?setSocketDescriptor@QAbstractSocket@@UEAA_N_JW4SocketState@1@V?$QFlags@W4OpenModeFlag@QIODevice@@@@@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual void __cdecl QAbstractSocket::setSocketOption(enum QAbstractSocket::SocketOption,class QVariant const &)" (?setSocketOption@QAbstractSocket@@UEAAXW4SocketOption@1@AEBVQVariant@@@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual __int64 __cdecl QAbstractSocket::socketDescriptor(void)const " (?socketDescriptor@QAbstractSocket@@UEBA_JXZ) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual class QVariant __cdecl QAbstractSocket::socketOption(enum QAbstractSocket::SocketOption)" (?socketOption@QAbstractSocket@@UEAA?AVQVariant@@W4SocketOption@1@@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual bool __cdecl QAbstractSocket::waitForBytesWritten(int)" (?waitForBytesWritten@QAbstractSocket@@UEAA_NH@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual bool __cdecl QAbstractSocket::waitForConnected(int)" (?waitForConnected@QAbstractSocket@@UEAA_NH@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual bool __cdecl QAbstractSocket::waitForDisconnected(int)" (?waitForDisconnected@QAbstractSocket@@UEAA_NH@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "public: virtual bool __cdecl QAbstractSocket::waitForReadyRead(int)" (?waitForReadyRead@QAbstractSocket@@UEAA_NH@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK2001 无法解析的外部符号 "protected: virtual __int64 __cdecl QAbstractSocket::writeData(char const *,__int64)" (?writeData@QAbstractSocket@@MEAA_JPEBD_J@Z) SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\SocketTCPClient\SocketTCPClient.obj 1
错误 LNK1120 27 个无法解析的外部命令 SocketTCPClient F:\Program\QT Code\TCP\SocketTCPClient\x64\Debug\\SocketTCPClient.exe 1
这是未添加QtNetwork库引起的问题。
可以通过Qt VS Tools中的Qt Project Settings添加: