Otto45
Otto45

Reputation: 595

Linker error when building project

When I try to build my project in Visual Studio 2010, I get the following errors:

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:\Users\aottinge\Documents\CS390CPP\WaveEdit\Debug\WaveEdit.exe : fatal error LNK1120: 2 unresolved externals

selectionStart and selectionEnd are defined in CWaveEditView, and I'm trying to access them in a function in the class WaveEditDoc. I'm getting no compiler errors, so I know I'm referencing everything correctly. Here's the section of code that's apparently causing the issue:

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();
    }
}

Upvotes: 0

Views: 276

Answers (1)

Enrico Granata
Enrico Granata

Reputation: 3339

The fact that you are getting no compiler errors only means that the compiler has seen a declaration of selectionStart and selectionEnd and that everything type checked

You are getting a linker error because there are no actual definitions of those symbols that are visible.

Obvious questions: where are the definitions of selectionStart and selectionEnd - and are you linking the Doc & View object files together such that the linker could match up the external symbol with its definition?

Upvotes: 3

Related Questions