Linker Tools Error LNK2001 (Windows CE 5.0)

Send Feedback

unresolved external symbol "symbol"

Code references something (such as a function, variable, or label) that the linker can't find in the libraries and object files.

The following list shows a possible cause for this error.s

  • What the code asks for doesn't exist (the symbol is spelled incorrectly or uses the wrong case, for example).
  • The code asks for the wrong thing (you are using mixed versions of the libraries, some from one version of the product, others from another version).

This error message is followed by fatal error LNK1120.

The following list shows coding problems which might be specific causes for this error.

  • Mismatched case in your code or module-definition (.def) file can cause LNK2001 (for example, if you named a variable var1 in one C++ source file and tried to access it as VAR1 in another).

  • A program that uses function inlining but defines the functions in a .cpp file rather than in the header file can cause LNK2001.

  • Calling a C function from a C++ program without using extern "C" (which causes the compiler to use the C naming convention) can cause LNK2001.

    Compiler options /Tp and /Tc cause the compiler to compile files as C or C++, respectively, regardless of the filename extension.

    These options can cause function names different from what you expect.

  • Attempting to reference functions or data that don't have external linkage can cause LNK2001. In C++, inline functions and const data have internal linkage unless explicitly specified as extern.

  • A missing function body or variable can cause LNK2001. With just a function prototype or extern declaration the compiler can continue without error, but the linker cannot resolve a call to an address or reference to a variable because there is no function code or variable space reserved.

  • Calling a function with parameter types that do not match those in the function declaration can cause LNK2001. Name decoration incorporates the parameters of a function into the final decorated function name.

  • Incorrectly included prototypes, which cause the compiler to expect a function body that is not provided can cause LNK2001. If you have a class and nonclass implementation of a function F, beware of C++ scope-resolution rules.

  • When using C++, including a function prototype in a class definition and failing to include the implementation of the function for that class can cause LNK2001.

  • Attempting to call a pure virtual function from the constructor or destructor of an abstract base class can cause LNK2001. A pure virtual function has no base class implementation.

  • Trying to access a static variable from outside the file in which it is declared can cause LNK2001. Functions declared with the static modifier by definition have file scope. Static variables have the same limitation.

  • Trying to use a variable declared within a function (a local variable) outside the scope of that function can cause LNK2001.

  • Trying to use a global constant in C++ in multiple files can cause LNK2001.

    In C++, unlike C, global constants have static linkage. To get around this limitation, include the const initializations in a header file and include that header in your .cpp files, or make the variable nonconstant and use a constant reference to access it.

  • When building a release version of an Active Template Library (ATL) for Windows CE project, indicates that CRT startup code is required. To fix, do one of the following,

    • Remove _ATL_MIN_CRT from the list of preprocessor defines to allow CRT startup code to be included.

      On the Project menu, click Settings.

      In the Settings For: drop down list, choose Multiple Configurations.

      In the Select project configuration(s) to modify dialog box, click the check boxes for all Release versions, and then click OK.

      On the C/C++ tab, choose the General category and remove _ATL_MIN_CRT from the Preprocessor definitions edit box.

    • If possible, remove calls to CRT functions that require CRT startup code. Instead, use their Microsoft® Win32® equivalents.

      For example, use lstrcmp instead of strcmp.

      Known functions that require CRT startup code are some of the string and floating point functions.

Compiling and Linking Problems

  • Using /NOD if the names of the run-time and Microsoft Foundation Classes (MFC) for Windows CE libraries are included in the object file module can cause LNK2001. If you use the /NOD (/NODEFAULTLIB) option, these libraries are not**linked into the project unless you have explicitly included them.

  • If you are using Unicode and MFC, you will get an unresolved external on _WinMain@16 if you do not create an entrypoint to wWinMainCRTStartup. Use the /ENTRY option or type this value in the Project Settings dialog box.

    To find this option in the development environment, click Settings on the Project menu, then click the Link tab and click Output in the Category box.

    For more information, see the following Knowledge Base articles in the MSDN Library. In the MSDN Library, click the Search tab, paste the article number or article title into the text box, then click List Topics. If you search on the article number, make sure the Search titles only option is clear.

    • Q125750   "PRB: Error LNK2001: '_WinMain@16': Unresolved External Symbol"
    • Q131204   "PRB: Wrong Project Selection Causes LNK2001 on _WinMain@16"
    • Q100639   "Unicode Support in the Microsoft Foundation Class Library"
  • Linking code compiled with /MT with the library LIBC.lib causes LNK2001 on _beginthread, _beginthreadex, _endthread, and _endthreadex.

  • When compiling with /MD, a reference to "func" in your source becomes a reference "__imp__func" in the object because all the run-time is now held within a DLL.

    If you try to link with the static libraries LIBC.lib or LIBCMT.lib, you get LNK2001 on __imp__func.

    If you try to link with MSVCxx.lib when compiling without /MD you do not always get LNK2001, but you will likely have other problems.

  • Linking code compiled with an explicit or implicit /ML to the LIBCMT.lib causes LNK2001 on _errno.

  • Linking with the release mode libraries when building a debug version of an application can cause LNK2001. Similarly, using an /Mxd option (/MLd, /MTd, or /MDd) and/or defining _DEBUG and then linking with the release libraries will give you potential unresolved externals (among other problems). Linking a release mode build with the debug libraries also causes similar problems.

  • Mixing versions of Microsoft libraries and compiler products can be problematic. A new compiler version's libraries can contain new symbols that cannot be found in the libraries included with previous versions. Use DUMPBIN to find out if a symbol is in a 32-bit object file or library.

  • There is no standard for C++ naming between compiler vendors or between different versions of a compiler. Therefore, linking object files compiled with other compilers might not produce the same naming scheme and thus cause error LNK2001.

  • Mixing inline and noninline compile options on different modules can cause LNK2001. If a C++ library is created with function inlining turned on (/Ob1 or /Ob2) but the corresponding header file describing the functions has inlining turned off (no inline keyword), you will get this error.

    To prevent this problem, have the inline functions defined with inline in the header file you are going to include in other files.

  • If you are using the #pragma inline_depth compiler directive, make sure you have a value of 2 or greater set, and make sure you are using the /Ob1 or /Ob2 compiler option.

  • Omitting the LINK option /NOENTRY when creating a resource-only DLL causes LNK2001.

  • Using incorrect /SUBSYSTEM or /ENTRY settings can cause LNK2001. For example, if you write a character-based application (a console application) and specify /SUBSYSTEM:WINDOWS, you will get an unresolved external for WinMain.

Export Problems

  • When you are porting an application from 16 to 32 bits, LNK2001 can occur. The current 32-bit module-definition (.def) file syntax requires that __cdecl, __stdcall, and __fastcall functions be listed in the EXPORTS section without underscores (undecorated).

    This differs from the 16-bit syntax, where they must be listed with underscores (decorated).

    For more information, see the description of the EXPORTS section of module-definition files.

  • Any export listed in the .def file and not found will cause LNK2001. This could be because it does not exist, is spelled incorrectly, or uses C++ decorated names (.def files do not take decorated names)

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.