未解决的链接错误

Unresolved Link Error

本文关键字:错误 链接 未解决      更新时间:2023-10-16

在尝试编译时收到此错误。

error LNK2019: unresolved external symbol "public: void __thiscall Serial::WritePort(char * const)" (?WritePort@Serial@@QAEXQAD@Z) referenced in function "public: void __thiscall CThermotronDlg::OnBnClickedButton2(void)" (?OnBnClickedButton2@CThermotronDlg@@QAEXXZ)

我已经包含了所有必需的头文件,但当我试图在主对话框.cpp中调用我的WritePort函数(位于我的sConfig.cpp中)时,我会收到这个链接错误。另外,每个.cpp文件都在同一个文件夹中,所以我不会试图引用不同位置的文件。下面是WritePort函数和调用它的块的。

写入端口

void WritePort(char buffer[])
{
HANDLE sSerial = CreateFile(L"COM3",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
OpenPort();
DWORD bytes;
WriteFile(sSerial, buffer,sizeof(buffer),&bytes,NULL);
}

阻止

void CThermotronDlg::OnBnClickedButton2()

CString str; str.Format(L"%d",Index);
LPTSTR Dwell = new TCHAR[1000];
USES_CONVERSION;
char* buffer =T2A(Dwell);
MyListEx.GetItemText(Index,1,Dwell,1000);
Serial Port;
Port.WritePort(buffer);

AfxMessageBox(Dwell,MB_OK,NULL);

}

不应该

void WritePort(char buffer[])

void Serial::WritePort(char buffer[])

函数WritePort需要是Serial类的一部分,因为您将其用作Port.WritePort(buffer)而不是WritePort(buffer)

void Serial::WritePort(char buffer[])
{
bool umm;
HANDLE sSerial = CreateFile(L"COM3",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
OpenPort();
DWORD bytes;
umm = WriteFile(sSerial, buffer,sizeof(buffer),&bytes,NULL);
}
相关文章: