What is an Undefined Reference Error in C++? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In C++, an undefined reference is an error that occurs when the linker can't find the definition of a function or a variable used in the linking stage of the compilation process. This error needs to be resolved for the smooth working of the program. When Does Undefined Reference Error Occur in C++?An undefined reference error is a linker error, not a compiler error. It appears when the code refers to a symbol (function or variable) whose declaration is known, but whose definition is missing. We get undefined reference errors due to the following reasons: Function or Variable Declaration Without Definition.Incorrect Scope Resolution.Incorrect Linking of Object Files or Libraries.Example of Undefined Reference ErrorThe below example demonstrates the occurrence of an undefined reference error due to a missing function definition. C++ // C++ example demonstrating an undefined reference error. #include <iostream> // Declare `newFunction` but don't provide its // implementation. void newFunction(); int main() { // Calling this triggers an error because `newFunction` // is undefined. newFunction(); return 0; } Output /usr/bin/ld: /tmp/cceTEmEf.o: in function `main': main.cpp:(.text+0x9): undefined reference to `newFunction()' collect2: error: ld returned 1 exit statusTo resolve this, make sure to provide a proper definition for the function: C++ // C++ program demonstrating a corrected undefined reference // error #include <iostream> using namespace std; // Function that prints "This is new function" void newFunction() { cout << "This is new function"; } int main() { newFunction(); return 0; } OutputThis is new functionHow to Avoid Undefined Reference Error in C++ To avoid undefined errors in our C++ program, we can follow the given steps: Double-check function definitions for consistency with declarations.Verify that all necessary header files are included.Inspect library linking instructions and ensure proper library paths.Scrutinize code for typos and misspellings in object names.Use a debugger to pinpoint the exact source file and line where the error originates. To know more about how to fix these kinds of errors, refer to this article - How to fix undefined error in C++? Comment More infoAdvertise with us Next Article What is an Undefined Reference Error in C++? H heysaiyad Follow Improve Article Tags : C++ Programs C++ C++ Errors CPP Examples Practice Tags : CPP Similar Reads How to Fix Undefined Reference Error in C++? In C++, the undefined reference error typically occurs during the linking phase of compilation. This error indicates that the compiler knows about a function or variable (it has been declared), but it cannot find the actual implementation (definition) during the linking process. The linker needs to 2 min read Reason of runtime error in C/C++ In this article, we will discuss the reason for the run-time error and its solution. Runtime Error: A runtime error in a program is an error that occurs while the program is running after being successfully compiled. Below are some methods to identify the reason behind Runtime errors:Â Method 1: Whe 3 min read Why Assignment Operator Overloading Must Return Reference? Operator overloading in C++ allows us to define custom behaviors for operators when applied to user-defined types. One of the most commonly overloaded operators is the assignment operator (=), which is used to assign the value of one object to another. However, when overloading the assignment operat 4 min read Different ways to use Const with Reference to a Pointer in C++ Before moving forward with using const with Reference to a Pointers, let us first see what they are one by one: Pointers are used to store the address of variables or a memory location. A variable can be declared as a pointer by putting â*â in the declaration. datatype *var_name; Example: CPP // C++ 5 min read Overloads of the Different References in C++ This article focuses on function/method overloads by references, as well as the types of arguments that can be passed. Prerequisites: l-value references.r-value references.Move semantics - std::move(). Overview:l-value refers to a memory location that identifies an object. r-value refers to the data 12 min read How to add reference of an object in Container Classes We all are familiar with an alias in C++. An alias means another name for some entity. So, a reference variable is an alias that is another name for an existing variable/object etc. Below is the program for adding reference to a variable: CPP // C++ program to illustrate // aliasing in variable #inc 4 min read Difference Between *& and **& in C++ In C++, the *& (pointer to reference) and **&(pointer to pointer reference) symbols are used in the context of pointers and references for manipulating memory addresses and dealing with complex data structures. While they seem similar, they serve different purposes. In this article, we will 5 min read How to Define a Move Constructor in C++? In C++, we have a move constructor which is a part of C++11 move semantics and is used to handle resources for temporary and rvalue objects. In this article, we will learn how to write a move constructor in C++. How to Write Move Constructor in C++?The move constructor is defined similarly to a copy 2 min read How to fix auto keyword error in Dev-C++ The auto keyword in C++ specifies that the type of the variable that is being declared will be automatically deducted from its initializer. In case of functions, if their return type is auto then that will be evaluated by return type expression at runtime. CPP // C++ program to illustrate the auto / 2 min read Difference Between Pointers and Array Notations in C++ In C++, pointers and array notations are two ways using which we work with arrays and memory for accessing the data. They have distinct behaviours and are used in different contexts. In this article, we will learn the key differences between pointers and array notations in C++. Difference Between Po 4 min read Like