A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
Hello @MkJ ,
According to Microsoft’s documentation, LNK2019: unresolved external symbol means the compiler accepted a declaration of a symbol, but during the link step the linker could not find the matching definition in any compiled object file (.obj) or linked library (.lib). There is no special Visual Studio setting required to put class declarations in a header (.h) and definitions in a source file (.cpp). If you get LNK2019 when the definition is in the .cpp, it could be these below:
- The
.cppfile that contains the definitions is not being compiled/linked into the final build. - The definition in the
.cppdoes not exactly match the declaration in the header.
Also, moving the definitions into the header doesn’t prove the original .cpp was compiled, when the definition is in the header, it gets compiled into whatever .cpp includes that header.
I suggest you check the following:
- Make sure the
.cppis included in the project:
- In Solution Explorer, confirm the
.cppfile that contains the class definitions appears under Source Files of the same project that builds the.exe. - If the file exists on disk but isn’t added to the project, it won’t be compiled.
- Make sure the
.cppis not excluded from the build:
- Right‑click the
.cpp-> Properties - Configuration Properties -> General
- Item Type =
C/C++ Compiler - Excluded From Build =
No
- Item Type =
- Verify this for the active Configuration/Platform (Debug vs Release, Win32 vs x64).
- If you have multiple projects (EXE + library), link the right one
- If the class is defined in a different project (static lib/DLL), your EXE project must add a Project Reference (or link the correct
.lib).
- Verify declaration == definition:
- Missing
const, wrong namespace, different parameter types, calling convention, etc.
Example mismatch that causes LNK2019:
// header
void SayHello() const;
// cpp (wrong: missing const)
void MyClass::SayHello() { }
I hope this helps clarify your question. If you found my response helpful, you could follow this guide to provide feedback.
Thank you.