Question

I hate these linker errors, any idea how I can get rid of them?

Error   2   fatal error LNK1120: 1 unresolved externals C:\Users\**********\Documents\Visual Studio 2005\Projects\Machine2\Debug\Machine2.exe

and

Error   1   error LNK2001: unresolved external symbol "public: void __thiscall SecondDlg::OnBnClickedButton4(void)" (?OnBnClickedButton4@SecondDlg@@QAEXXZ) SecondDlg.obj
Was it helpful?

Solution 4

I deleted ON_BN_CLICKED(IDC_BUTTON4, &SecondDlg::OnBnClickedButton4) and all other instances of IDC_BUTTON4. My compiler was trying to compile something that wasn't there anymore.

OTHER TIPS

The error comes probably from one of the following causes:

  • You forgot to implement the method in the cpp file
  • The cpp file is not included in the compilation
  • You forgot to export your class with _declspec(dllexport)
  • You're not linking against the library where SecondDlg resides

public: void __thiscall SecondDlg::OnBnClickedButton4(void)

The linker is trying it's best telling you that the call to SecondDlg::OnBnClickedButton4(void) can not be resolved. Which means that it is unable to find the definition of the member function from any source( object file to be precise ) file that got compiled. You just provided the declaration in interface but not it's definition( i.e., implementation ) any where.

Well i don't have much information to understand what's is going on. Are you sure you wrote the OnBnClickedButton4 method? Maybe is just declared. Look into your C++ files.

Can you show us the declaration of the method? Can you give us more informations?

Maybe you are using the keyword "extern" when is not needed?

This would help others who read this Q&A, even though this specific problem has been solved.

I've had these linker errors before and eliminating the use of the global variable in general seemed to be the answer. The use of non-const global variables only confuses the compiler and linker (and the programmer), especially as your program grows in size.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top