未解析的外部符号-仅在释放模式下

Unresolved External Symbol - Only in Release mode

本文关键字:释放 模式 符号 外部      更新时间:2023-10-16

我使用的是Visual C++6,我的应用程序在调试模式下构建和运行良好,但在发布模式下构建时,我会遇到以下两个未解决的外部符号错误:

OverUnderReportDoc.obj : error LNK2001: unresolved external symbol "public: virtual int     __thiscall COverUnderReportDoc::GenerateReport(void)" (? GenerateReport@COverUnderReportDoc@@UAEHXZ)
OverUnderReportDoc.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall COverUnderReportDoc::DoReport(void)" (?DoReport@COverUnderReportDoc@@UAE_NXZ)

COverUnderReportDoc是一个派生自CReportDoc的类,CReportDoc派生自MFC框架的CDocument。

以下是函数声明:

public:
virtual int GenerateReport(void);
virtual bool DoReport(void);

定义:

bool COverUnderReportDoc::DoReport(void)
{
// Instantiate the dialog
CCriteriaDlg dlg;
m_Report.BreakSpace(FALSE);
// Get a pointer to the window
CWnd* pWnd = AfxGetApp()->m_pMainWnd;
// When OK is clicked...
if (dlg.DoModal() == IDOK)
{       
    // Set the document title
    SetTitle("Inventory Over/Under");
    // Copy some values from the dialog to member variables
    GenerateReport();
    pWnd->ShowWindow(SW_MAXIMIZE);
}
else
{
            // If Cancel is clicked, close the program
    if(pWnd)
        pWnd->PostMessage(WM_CLOSE);
    return false;
}
return true;
}
int COverUnderReportDoc::GenerateReport(void)
{
// write the headers to the report
// if there was no problem
if (DoHeaders())
{
    // assemble the report data
    // if that went well
    if (ScanFile())
        // write the summary to the report
        DoSummary();
}
// return the document status
return m_nStatus;
}

我真的不知道如何解决这个问题,这些方法不在任何库中,而且类编译得很好,所以我不知道为什么它在链接时看不到它们。有人有什么想法吗?

编辑:以下是我的项目选项:

发布项目选项:

Project SettingsC/C++选项卡)

/nologo /Zp1 /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /D   "_MBCS" /D "BTI_WIN_32" /FR"Release/" /Fo"Release/" /Fd"Release/" /FD /c 

Project SettingsLink选项卡)

MYLIB.lib w3btrv7.lib VERSION.LIB /nologo /subsystem:windows /incremental:no /pdb:"Release/OverUnderReport.pdb" /machine:I386 /out:"Release/OverUnderReport.exe" 

调试项目选项:

Project SettingsC/C++选项卡)

/nologo /Zp1 /MDd /W3 /GX /ZI /Ot /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /D "BTI_WIN_32" /FR"Debug/" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c

Project SettingsLink选项卡)

VERSION.LIB MYLIB.lib w3btrv7.lib /nologo /subsystem:windows /profile /debug /machine:I386 /out:"Debug/OverUnderReport.exe" 

第102行,位于pastebin.com/e1E0WcBT:

#ifdef _DEBUG

导致在发布模式下构建时从那时起跳过成员函数的所有定义。