# What are undefined reference/unresolved external symbol errors in C++?

C++Server Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

Best Seller

66 Lectures 5.5 hours

As the name suggests, a symbol you declared was not defined by you. This may occur due to many cases. Let's have a look at three of them −

• You forgot to define the declared name. For example, you declared a function in a file and used it somewhere. But you did not provide its definition. Code −

#include<iostream>
void foo();
int main() {
foo(); // Declared but not defined
}
• You defined it but did not use the qualified name. Say you created a class with a method and defined that method but forgot using scope resolution to link that function to that definition and used that function somewhere. For example,

#include<iostream>
class A {
void foo();
};
void foo() { } // should have used A::foo
int main() {
A a;
a.foo(); // Not defined!
}
• You did not include dependencies in incorrect order. The linker tries to link in the order you specify to it. So in case you use a method before its definition, it will likely give this error.

Creating an exhaustive list of conditions that can cause this error is not possible. But you can refer to this post for a very well-curated list of likely reasons − https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix

Updated on 23-Jun-2020 13:26:30