【发布时间】:2013-02-06 16:18:08
【问题描述】:
我在尝试编译时收到此错误。
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)
我已经包含了所有必需的头文件,但是当我尝试在我的主 dialog.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);
}
【问题讨论】:
-
某事告诉我看到
Serial的实现或更重要的是,缺少任何Serial::WritePort实现的代码(注意类限定符)会导致您遇到问题,并最终解决它。
标签: c++ function mfc dialog lnk2019