PRB: LNK1120 Error Gives You the Number of Unresolved Externals (815650)



The information in this article applies to:

  • Microsoft Visual C++

SYMPTOMS

When you build a C application or a C++ application, and the linker cannot resolve external symbols, you may receive the following LNK1120 linker error message:
fatal error LNK1120: x unresolved externals
where x is the number of external symbols that the linker cannot resolve.

RESOLUTION

To resolve the LNK1120 errors, use the following /LIBPATH option:
/LIBPATH:dir
where dir specifies a path that the linker searches before it searches the path that is specified in the LIB environment variable. For more information, visit the following Microsoft Developer Network (MSDN) Web site:

STATUS

This behavior is by design.

MORE INFORMATION

For more information about the conditions that cause unresolved external symbols, visit the following MSDN Web site:The symbols that the linker cannot resolve are described with the LNK2001 error message. The LNK2001 error message comes before the LNK1120 error message. You receive the LNK2001 error message for each unresolved external symbol.

Steps to Reproduce the Behavior

  1. Paste the following code in Notepad, and then save the file:
    //The prototypes of functions fun1(), fun2() and fun3()
    void fun1(void);
    void fun2(void);
    void fun3(void);
    
    // This is the entry point for this application
    int main(void)
    {
    	fun1();
    	fun2();
    	fun3();
    
    	return 0;
    }
  2. Use the following to compile the application:
    cl /c <filename.cpp>
    where filename is the name of the file that you created and saved in step 1.

    Note: To compile the program in Microsoft Visual Studio .NET, use the Microsoft Visual Studio .NET command prompt.

    To compile the program in Microsoft Visual Studio 6.0 and earlier, run vcvars32.bat from the command prompt.
  3. Link the object file as follows:
    Link <filename.obj>
The following linker errors appear at the command prompt:
error LNK2001: unresolved external symbol "void __cdecl fun3(void)" (?fun3@@$$FYAXXZ)
error LNK2001: unresolved external symbol "void __cdecl fun2(void)" (?fun2@@$$FYAXXZ)
error LNK2001: unresolved external symbol "void __cdecl fun1(void)" (?fun1@@$$FYAXXZ)
fatal error LNK1120: 3 unresolved externals
Notice that the LNK1120 error message gives you the number of unresolved external symbols that the linker found.

Modification Type:MajorLast Reviewed:7/25/2003
Keywords:kbprb kberrmsg KB815650 kbAudDeveloper kbAudITPRO