LNK2019
Visual C++ Programming Language
Severity: ModerateWhat Does This Error Mean?
LNK2019 means the linker found a declaration (in a header) for a function or variable, but could not find its definition (the actual implementation). This is the most common linker error in Visual C++. The message names the symbol: LNK2019: unresolved external symbol 'function_name' referenced in function 'caller'. Adding the missing .lib file or the missing .cpp file to the project fixes it.
Affected Models
- Visual Studio 2015–2022
- MSVC Linker (link.exe)
Common Causes
- A .cpp file that contains the function definition is not included in the project
- A required .lib library file is not listed in the linker's Additional Dependencies
- The function is declared in a header but its definition was never written
- Calling convention mismatch — function declared as __cdecl but defined as __stdcall (or vice versa)
- Missing extern "C" wrapper when mixing C and C++ code
How to Fix It
-
Read the error — it names the missing symbol. Search your codebase for a definition of that function or variable (not just a declaration).
A declaration is: void MyFunc(); A definition is: void MyFunc() { /* body */ } LNK2019 means a definition is missing.
-
If the symbol comes from a library (.lib file), add it to the project. In Visual Studio: Project Properties > Linker > Input > Additional Dependencies. Add the library name, e.g. opengl32.lib.
Many Windows APIs require specific .lib files: ws2_32.lib for WinSock, d3d11.lib for Direct3D, etc. The SDK documentation always lists which .lib to link.
-
If the symbol is in your own code, check that the .cpp file containing the definition is added to the project. Right-click the project in Solution Explorer > Add > Existing Item.
A file that exists on disk but is not in the project is not compiled or linked. Visual Studio Solution Explorer shows all files in the project — if the .cpp is missing from the list, it is not being compiled.
-
Check for calling convention mismatches. If the declaration and definition use different calling conventions (__cdecl vs __stdcall), the linker treats them as different symbols.
This is common when linking against Windows API functions or COM interfaces. Make the declaration and definition use the same calling convention keyword.
Frequently Asked Questions
What is the difference between LNK2019 and LNK2001?
LNK2019 is the primary error: a symbol was referenced but no definition was found. LNK2001 is a secondary error that often accompanies LNK2019 — it means a symbol that was needed by another unresolved symbol is also missing. Fix LNK2019 errors first — LNK2001 errors usually disappear automatically.
I included the header but still get LNK2019 — why?
The header provides the declaration, but LNK2019 is about the definition. Including the header tells the compiler the function exists — but the linker still needs the compiled object code (from a .cpp) or a library (.lib) that contains the actual implementation.