bigbaz34
bigbaz34

Reputation: 395

Linker errors LNK1120 and LNK2001

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

Upvotes: 1

Views: 4198

Answers (5)

BrennickC
BrennickC

Reputation: 101

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.

Upvotes: 0

bigbaz34
bigbaz34

Reputation: 395

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.

Upvotes: 1

Luchian Grigore
Luchian Grigore

Reputation: 258638

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

Upvotes: 7

Mahesh
Mahesh

Reputation: 34625

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.

Upvotes: 5

Salvatore Previti
Salvatore Previti

Reputation: 9080

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?

Upvotes: 1

Related Questions