相关文章推荐
坚强的椅子  ·  php 字符转ansi,php – ...·  10 月前    · 
腹黑的水龙头  ·  Python 3 中 Redis ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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
Error   1   error LNK2001: unresolved external symbol "public: void __thiscall SecondDlg::OnBnClickedButton4(void)" (?OnBnClickedButton4@SecondDlg@@QAEXXZ) SecondDlg.obj
  • 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
  • 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.

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.