You receive a "fatal error LNK1181" error message when you build a Managed C++ application (815645)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2003)
  • Microsoft Visual C++ .NET (2002)
  • Microsoft Linker (LINK.EXE)
  • Microsoft Visual C++ 2005 Express Edition

SYMPTOMS

This article describes linker error LNK1181. When you build a Managed C++ application, you may receive the following error message:
fatal error LNK1181: cannot open input file filename

CAUSE

This error occurs because the linker cannot find the file name or the file path that is specified in the project properties. However, the file path that is mentioned in the project properties is correct because the linker does not handle the space character in the file path.

RESOLUTION

To resolve this error, use the path without space characters, or use quotation marks around the path in project properties.

STATUS

This behavior is by design.

MORE INFORMATION

LNK1181 occurs when the .lib or .obj files that are specified during linking, are not found in the current directory, any of the directories that are specified by the LIBPATH linker option, or any of the directories that are specified in the LIB environment variable.

The error may occur in the following scenarios:
  • Scenario 1:

    If the library that generates the error was added to the project with a fully qualified path, the path may be invalid. The path is invalid if it is not present on the system or if the path contains space characters.
    1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
    2. On the File menu, point to New, and then click Project.
    3. In Visual C++ .NET 2002, click Visual C++ Projects under Project Types, and then click Managed C++ Application under Templates.

      In Visual C++ .NET 2003, click Visual C++ Projects under Project Types, and then click Console Application (.NET) under Templates.

      In Visual C++2005, click Visual C++ under Project Types, and then click CLR Console Application under Templates.
    4. In the Name text box, type TestLib.
    5. In the Location text box, type C:\Test, and then click OK.
    6. In Solution Explorer, right-click the project, and then click Properties.
    7. In the Property Pages dialog box, expand Linker, and then click Input.
    8. In the Additional Dependencies field, type the library file. For example, you can type C:\Program Files\mylib\mylib.lib.

      You may receive the following error message when you build the project:
      fatal error LNK1181: cannot open input file 'C:\Program.obj'
  • Scenario 2:

    The linker error LNK1181 may also occur if you add an unqualified file to the Additional Dependencies project property, and that file does not exist in any of the search directories that are defined in the LIB environment variable or the /LIBPATH project property.
    You may add the directory that contains library file to the LIBPATH to resolve the problem:
    1. In Solution Explorer, right-click the project, and then click Properties.
    2. In the Property Pages dialog box, expand Linker, and then click General.
    3. In the Additional Library Directories field, specify the required library path.

REFERENCES

For additional information about possible causes for this error message, see the following Microsoft Developer Network (MSDN) Web site for the similar LNK1104 linker error message:

Modification Type:MajorLast Reviewed:1/10/2006
Keywords:kbprb kbLangCPP kbCompiler KB815645 kbAudDeveloper