Share via


Linker Tools Error LNK2019 (Windows CE 5.0)

Send Feedback

unresolved external symbol 'symbol' referenced in function 'function'

An undefined external symbol (symbol) was found in function. To resolve this error, provide a definition for symbol or remove the code that references it.

This error can be caused when a variable is not defined in one of the files included in a build. In the following example, if i and g are not defined in one of the files included in the build, the linker will generate LNK2019.

extern int i;
extern void g();
void f()
{
   i++;
   g();
}
int main()
{
}

These definitions can be added by including the source code file that contains the definitions as part of the compilation. Alternatively, you can pass .obj or .lib files that contain the definitions to the linker.

Common problems that cause LNK2019 include:

  • The DLL being built cannot link against coredll, but the DLL contains an integer division operation that is normally exported by coredll.

    This issue typically occurs when implementing an installable ISR on an ARM microprocessor. To fix the issue, set the following variable in the SOURCES file:

    NOMIPS16CODE=1
    

    This variable enables the /QRimplicit-import compiler option and prevents importing external functions.

  • The declaration of the symbol contains a spelling mistake, such that, it is not the same name as the definition of the symbol.

  • A function was used but the type or number of the parameters did not match the function definition.

  • The calling convention ( __cdecl, __stdcall, or __fastcall) differs on the use of the function declaration and the function definition.

  • Symbol definitions are in a file that was compiled as a C program and symbols are declared in a C++ file without an extern "C" modifier. In that case, modify the declaration, for example, instead of:

    extern int i;
    extern void g();
    

    use:

    extern "C" int i;
    extern "C" void g();
    

    Similarly, if you define a symbol in a C++ file that will be used by a C program, use extern "C" in the definition.

  • A symbol is defined as static and then later referenced outside the file.

  • A static member of a class is not defined. For example, member variable si in the class declaration below should be defined separately:

    #include <stdio.h>
    struct X {
       static int si;
    };
    // int X::si = 0;   // uncomment this line to resolve
    void main()
    {
       X *px = new X[2];
       printf("\n%d",px[0].si);   // LNK2019
    }
    

The /VERBOSE linker option will help you see which files the linker is referencing. The /EXPORT and /SYMBOLS options of the DUMPBIN utility can also help you see which symbols are defined in your dll and object/library files.

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.