MSVC build errors > LNK2019
LNK2019: unresolved external symbol
error LNK2019: unresolved external symbol "int __cdecl Compute(int)" (?Compute@@YAHH@Z) referenced in function main
The compiler found a declaration of the function or variable, so the code compiled, but the linker found no definition of it in any object file or library it was given. The message names the missing symbol and the function that uses it.
Causes and fixes
- The function is declared but never defined. Write its body, or remove the call. A declaration in a header is only a promise that a definition exists somewhere.
- The
.cppfile that defines it is not part of the project. Add the file to the project in Solution Explorer: a file on disk that is not in the project is never compiled. - The library that defines it is not linked. Add the
.libto Linker > Input > Additional Dependencies and its folder to Linker > General > Additional Library Directories, for every configuration and platform. For a library built in the same solution, add a project reference instead. - The declaration and the definition do not match. Compare the signature: a missing
const, a different parameter type, another namespace, or a member function defined without itsClass::prefix declares a different symbol. - C code is called from C++ without
extern "C". Wrap the C declarations inextern "C" { }in the header, so that C++ looks for the undecorated name. - A template or an inline function is defined in a
.cppfile. Move its definition to the header: it must be visible wherever it is used. - The library was built for another platform. Link the x64 library in x64 builds and the x86 library in Win32 builds.
mainorWinMainis missing. An unresolvedmainreferenced ininvoke_mainmeans that Linker > System > SubSystem does not match the entry point: Console expectsmain, Windows expectsWinMain.
Fix LNK2019 with CppPilot
CppPilot reads the error, your code, and the project settings Visual Studio evaluates for the active configuration, then explains which of these causes applies. Choose Fix and the AI corrects it; CppPilot rebuilds the project and checks that the error is gone. Every change appears in Visual Studio for your approval.
Let the AI fix it in Visual Studio
CppPilot is a free extension that explains and fixes MSVC build errors with Codex, Claude, or CppPilot Cloud.
Related errors: LNK2001, LNK1120, LNK1104, LNK2005. See all guides.