生成项目时出现链接器错误

Linker error when building project

本文关键字:链接 错误 项目      更新时间:2023-10-16

当我尝试在Visual Studio 2010中构建项目时,出现以下错误:

1>WaveEditDoc.obj : error LNK2001: unresolved external symbol "public: static int CWaveEditView::selectionEnd" (?selectionEnd@CWaveEditView@@2HA)
1>WaveEditView.obj : error LNK2019: unresolved external symbol "public: static int CWaveEditView::selectionEnd" (?selectionEnd@CWaveEditView@@2HA) referenced in function "public: virtual void * __thiscall CWaveEditView::`scalar deleting destructor'(unsigned int)" (??_GCWaveEditView@@UAEPAXI@Z)
1>WaveEditDoc.obj : error LNK2001: unresolved external symbol "public: static int CWaveEditView::selectionStart" (?selectionStart@CWaveEditView@@2HA)
1>WaveEditView.obj : error LNK2019: unresolved external symbol "public: static int CWaveEditView::selectionStart" (?selectionStart@CWaveEditView@@2HA) referenced in function "public: virtual __thiscall CWaveEditView::~CWaveEditView(void)" (??1CWaveEditView@@UAE@XZ)
1>C:UsersaottingeDocumentsCS390CPPWaveEditDebugWaveEdit.exe : fatal error LNK1120: 2 unresolved externals

selectionStartselectionEnd是在CWaveEditView中定义的,我正在尝试在WaveEditDoc类的函数中访问它们。 我没有收到编译器错误,所以我知道我正确地引用了所有内容。 以下是显然导致此问题的代码部分:

void CWaveEditDoc::OnToolsPlay()
{
    // TODO: Add your command handler code here
    if(CWaveEditView::selectionStart!=CWaveEditView::selectionEnd){
        WaveFile * selection = new WaveFile(wave.numChannels, wave.sampleRate, wave.bitsPerSample);
        int i = CWaveEditView::selectionStart;
        while(i<=CWaveEditView::selectionEnd){
            selection->add_sample(wave.get_sample(i));
        }
        selection->play();
        delete selection;
    }else{
    wave.play();
    }
}

您没有收到编译器错误的事实仅意味着编译器已经看到了 selectionStart 和 selectionEnd 的声明,并且所有类型都已检查

您收到链接器错误,因为没有可见的这些符号的实际定义

显而易见的问题:selectionStart和selectionEnd的定义在哪里 - 您是否将Doc & View对象文件链接在一起,以便链接器可以将外部符号与其定义匹配?