Avatar ·

Error "undefined reference/unresolved external symbol" in C++: causes and fix

Hello everyone! I'm a beginner in C++ and have been struggling with an error for several hours that I can't understand. The compiler outputs something like:\n\n```\nundefined reference to `MyClass::myFunction()'\n```\nor\n```\nunresolved external symbol "public: void __thiscall MyClass::myFunction(void)" (?myFunction@MyClass@@QAEXXZ) referenced in function _main\n```\n\nHere is my code. I have three files:\n\n**main.cpp:**\n```cpp\n#include "myclass.h"\n\nint main() {\n MyClass obj;\n obj.myFunction();\n return 0;\n}\n```\n\n**myclass.h:**\n```cpp\n#ifndef MYCLASS_H\n#define MYCLASS_H\n\nclass MyClass {\npublic:\n void myFunction();\n};\n\n#endif\n```\n\n**myclass.cpp:**\n```cpp\n#include "myclass.h"\n#include \n\nvoid MyClass::myFunction() {\n std::cout << "Hello from myFunction!" << std::endl;