Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8572771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:06:06+00:00 2026-06-11T19:06:06+00:00

What are undefined reference/unresolved external symbol errors? What are common causes, and how do

  • 0

What are undefined reference/unresolved external symbol errors? What are common causes, and how do I fix and prevent these errors?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:06:07+00:00Added an answer on June 11, 2026 at 7:06 pm

    Say you have the following code:

    // a.cpp
    int get() { return 0; }
    
    // b.cpp
    int get(); // usually, one doesn't write this directly, but gets these
               // declarations from included header files
    int x = get();
    

    When compiling b.cpp, the compiler simply assumes that get() symbol was defined somewhere, but it doesn’t yet care where. The linking phase is responsible for finding the symbol and correctly linking the object files produced from a.cpp and b.cpp.

    If a.cpp didn’t define get, you would get a linker error saying "undefined reference" or "unresolved external symbol".

    C++ Standard Wording

    Compiling a C++ program takes place in several phases specified in [lex.phases], the last of which is relevant:

    9. All external entity references are resolved.
    Library components are linked to satisfy external references to entities not defined in the current translation.
    All such translator output is collected into a program image which contains information needed for execution in its execution environment.

    See Keith Thompson’s answer for a summary of these phases.

    The specified errors occur during this last stage of compilation, most commonly referred to as linking. It basically means that you compiled a bunch of source files into object files or libraries, and now you want to get them to work together.

    Linker Errors in Practice

    If you’re using Microsoft Visual Studio, you’ll see that projects generate .lib files. These contain a table of exported symbols, and a table of imported symbols. The imported symbols are resolved against the libraries you link against, and the exported symbols are provided for the libraries that use that .lib (if any).

    Similar mechanisms exist for other compilers/ platforms.

    Common error messages are error LNK2001, error LNK1120, error LNK2019 for Microsoft Visual Studio and undefined reference to symbolName for GCC.

    The code:

    struct X
    {
       virtual void foo();
    };
    struct Y : X
    {
       void foo() {}
    };
    struct A
    {
       virtual ~A() = 0;
    };
    struct B: A
    {
       virtual ~B(){}
    };
    extern int x;
    void foo();
    int main()
    {
       x = 0;
       foo();
       Y y;
       B b;
    }
    

    will generate the following errors with GCC:

    /home/AbiSfw/ccvvuHoX.o: In function `main':
    prog.cpp:(.text+0x10): undefined reference to `x'
    prog.cpp:(.text+0x19): undefined reference to `foo()'
    prog.cpp:(.text+0x2d): undefined reference to `A::~A()'
    /home/AbiSfw/ccvvuHoX.o: In function `B::~B()':
    prog.cpp:(.text._ZN1BD1Ev[B::~B()]+0xb): undefined reference to `A::~A()'
    /home/AbiSfw/ccvvuHoX.o: In function `B::~B()':
    prog.cpp:(.text._ZN1BD0Ev[B::~B()]+0x12): undefined reference to `A::~A()'
    /home/AbiSfw/ccvvuHoX.o:(.rodata._ZTI1Y[typeinfo for Y]+0x8): undefined reference to `typeinfo for X'
    /home/AbiSfw/ccvvuHoX.o:(.rodata._ZTI1B[typeinfo for B]+0x8): undefined reference to `typeinfo for A'
    collect2: ld returned 1 exit status
    

    and similar errors with Microsoft Visual Studio:

    1>test2.obj : error LNK2001: unresolved external symbol "void __cdecl foo(void)" (?foo@@YAXXZ)
    1>test2.obj : error LNK2001: unresolved external symbol "int x" (?x@@3HA)
    1>test2.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall A::~A(void)" (??1A@@UAE@XZ)
    1>test2.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall X::foo(void)" (?foo@X@@UAEXXZ)
    1>...\test2.exe : fatal error LNK1120: 4 unresolved externals
    

    Common Causes

    • Failure to link against appropriate libraries/object files or compile implementation files
    • Declared and undefined variable or function.
    • Common issues with class-type members
    • Template implementations not visible.
    • Symbols were defined in a C program and used in C++ code.
    • Incorrectly importing/exporting methods/classes across modules/dll. (MSVS specific)
    • Circular library dependency
    • undefined reference to `WinMain@16′
    • Interdependent library order
    • Multiple source files of the same name
    • Mistyping or not including the .lib extension when using the #pragma (Microsoft Visual Studio)
    • Problems with template friends
    • Inconsistent UNICODE definitions
    • Missing "extern" in const variable declarations/definitions (C++ only)
    • Visual Studio Code not configured for a multiple file project
    • Errors on Mac OS X when building a dylib, but a .so on other Unix-y systems is OK
    • Your linkage consumes libraries before the object files that refer to them
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What is an undefined reference/unresolved external symbol error and how do I
Possible Duplicate: What is an undefined reference/unresolved external symbol error and how do I
Possible Duplicate: Why do I get “unresolved external symbol” errors when using templates? Why
I've been trying to compile my project and I'm getting undefined reference errors. eg.:
When I compile my program, I get three undefined reference to 'PrintArgv(...)' errors. I
I have linkers errors(undefined reference) that I cannot solve by myself. I use GCC
I am facing a few problems with undefined reference to errors. I may not
Linking my program produces a bunch of errors like below. /home/starlon/Projects/LCDControl/DrvQt.cpp:8: undefined reference to
Possible Duplicate: GCC C++ Linker errors: Undefined reference to 'vtable for XXX', Undefined reference
I've checked the most common undefined reference to vtable question on here, and while

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.