G
Glam Ledger

How do I fix lnk2001 unresolved external symbol?

Author

John Peck

Published May 14, 2026

To fix this issue, add the /NOENTRY option to the link command. This error can occur if you use incorrect /SUBSYSTEM or /ENTRY settings in your project. For example, if you write a console application and specify /SUBSYSTEM:WINDOWS, an unresolved external error is generated for WinMain .

Similarly one may ask, how do I fix unresolved external symbol in C++?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.

Also, what is an unresolved external symbol? The compiler can identify when a symbol isn't declared, but it can't tell when the symbol isn't defined. If a symbol is referred to but never defined, the linker generates an unresolved external symbol error.

Correspondingly, what kind of an error is an unresolved external reference?

Unresolved external references occur when the symbol for a function or global variable is referenced in a program, but none of the object files or libraries specified in the link step contain a definition for that symbol.

How do I fix lnk2019 unresolved external symbol?

The short answer to your problem is that when building your UnitTest1 project, the compiler and linker have no idea that function. cpp exists, and also have nothing to link that contains a definition of multiple . A way to fix this is making use of linking libraries.

Related Question Answers

What is an external symbol?

A symbol referred to by an external reference must be an external name, the name of an entry point, or the name of a pseudoregister. In modules containing only a single text class, the section (CSECT or common area) name is an implied entry point. External references and external labels are called external symbols.

How do you compile a C++ program?

Compiling a Simple C++ Program
  1. Create a folder for our C++ program.
  2. Navigate to that folder.
  3. Create our C++ program from a text editor (I used Visual Studio Code)
  4. Compile our source code into object files.
  5. Link our object files to produce an executable file.

What is linker error?

Linker errors occur when the linker is trying to put all the pieces of a program together to create an executable, and one or more pieces are missing. Typically, this can happen when an object file or libraries can't be found by the linker.

What is an undefined symbol?

A symbol remains undefined when a symbol reference in a relocatable object is never matched to a symbol definition. Similarly, if a shared object is used to create a dynamic executable and leaves an unresolved symbol definition, an undefined symbol error results.

What goes in a header file C++?

Things like class declarations, function prototypes, and enumerations typically go in header files. In a word, "definitions". Code files ( . cpp ) are designed to provide the implementation information that only needs to be known in one file.

What are static variables in C++?

Static variables in a Function: When a variable is declared as static, space for it gets allocated for the lifetime of the program. So, its value is carried through the function calls. The variable count is not getting initialized for every time the function is called.

How do I fix my lnk2005?

Possible solutions include:
  1. Add the inline keyword to the function: h Copy. // LNK2005_func_inline.h inline int sample_function(int k) { return 42 * (k % 167); }
  2. Remove the function body from the header file and leave only the declaration, then implement the function in one and only one source file: h Copy.

What is undefined reference to main?

The error: undefined reference to 'main' in C program is a very stupid mistake by the programmer, it occurs when the main() function does not exist in the program. If you used main() function and still the error is there, you must check the spelling of the main() function.

How do I join two .cpp files?

Each definition should simply print out the function name, argument list, and return type so you know it's been called. Create a second . cpp file that includes your header file and defines int main( ), containing calls to all of your functions. Compile and run your program.

How do I link a DLL in Visual Studio?

To create a DLL project in Visual Studio 2017

On the menu bar, choose File > New > Project to open the New Project dialog box. In the left pane of the New Project dialog box, select Installed > Visual C++ > Windows Desktop. In the center pane, select Dynamic-Link Library (DLL).

What is the role of linker in software development?

Linker is a program in a system which helps to link a object modules of program into a single object file. It performs the process of linking. Linker are also called link editors. Linking is process of collecting and maintaining piece of code and data into a single file.

What extern C means?

extern "C" is a linkage specification which is used to call C functions in the Cpp source files. We can call C functions, write Variables, & include headers. Function is declared in extern entity & it is defined outside.

What does the compiler do when it encounters a symbol that is not defined in the current module?

When the compiler encounters a symbol (either a var or func name) that is not defined in the current module, it assumes that it is defined in some other module, generally a linker symbol table entry, and leaves it for the linker to handle.

How do you fix undefined symbol in C++?

5 Answers. You need to pass the values to the function Calculate. Variables x, y, z and function are not accessible outside the class and also u need a return type to the function so that you can get the output from the function Calculate. You are missing std:: qualifiers whenever you use cin , cout , or endl .

What is undefined reference in CPP?

Put simply, the “undefined reference” error means you have a reference (nothing to do with the C++ reference type) to a name (function, variable, constant etc.) in your program that the linker cannot find a definition for when it looks through all the object files and libraries that make up your project.

How do I fix error lnk1104?

This error can occur when the Visual Studio path to the Windows SDK is out of date. It may happen if you install a newer Windows SDK independently of the Visual Studio installer. To fix it in the IDE, update the paths specified in the VC++ Directories property page. Set the version in the path to match the new SDK.