Visual Studio: LINK : fatal error LNK1181: cannot open input file

243,956

Solution 1

In Linker, general, additional library directories, add the directory to the .dll or .libs you have included in Linker, Input. It does not work if you put this in VC++ Directories, Library Directories.

Solution 2

I can see only 1 things happening here: You did't set properly dependences to thelibrary.lib in your project meaning that thelibrary.lib is built in the wrong order (Or in the same time if you have more then 1 CPU build configuration, which can also explain randomness of the error). ( You can change the project dependences in: Menu->Project->Project Dependencies )

Solution 3

Go to:

Project properties -> Linker -> General -> Link Library Dependencies set No.

Solution 4

I recently hit the same error. Some digging brought up this: http://support.microsoft.com/kb/815645

Basically, if you have spaces in the path of the .lib, that's bad. Don't know if that's what's happening for you, but seems reasonably possible.

The fix is either 1) put the lib reference in "quotes", or 2) add the lib's path to your Library Directories (Configuration Properties >> VC++ Directories).

Solution 5

I had the same issue in both VS 2010 and VS 2012. On my system the first static lib was built and then got immediately deleted when the main project started building.

The problem is the common intermediate folder for several projects. Just assign separate intermediate folder for each project.

Read more on this here

Share:
243,956

Related videos on Youtube

Komn
Author by

Komn

Updated on February 15, 2022

Comments

  • Komn
    Komn over 2 years

    I've been encountering a strange bug in Visual Studio 2010 for some time now.

    I have a solution consisting of a project which compiles to a static library, and another project which is really simple but depends on this library.

    Sometimes, in the last days extremely frequent, after Rebuilding the Solution or just compiling it with 1-3 changed source files, I get the following error:

    2>LINK : fatal error LNK1181: cannot open input file 'thelibrary.lib'
    ========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========
    

    Where compiling thelibrary.lib was a success without any errors or warnings.

    I have tried cleaning the solution, but that doesn't always work.

    • What is wrong here?
    • thims
      thims over 12 years
      I have exactly the same issue. Solution with 3 native c++ projects. 1 exe and 2 static libs. Always getting mentioned error on Rebuild. After that I just do Build and it goes ok. Look like a bug.
    • Doan Quang Viet
      Doan Quang Viet over 7 years
      I have the same issue. I type only 'abc' instead of 'abc.lib'. After correct it, everything is done.
  • Komn
    Komn almost 13 years
    Thelibrary.lib is always built first. I have correctly set the depencies, long ago.
  • Sasha
    Sasha almost 13 years
    Well in this case it may be a VS bug. Try to find which process keeps the thelibrary.lib opened.
  • StraightCirle
    StraightCirle over 8 years
    Thank you for your solution, I did face these kind of problems and what you mentioned is right.If we have spaces in the library search path it will fail to detect the libraries. I am using visual studio 2013
  • rustyx
    rustyx about 8 years
    And what if I actually need the dependent library linked in? (Isn't that the main reason to specify the lib as a dependency in the first place)
  • kayleeFrye_onDeck
    kayleeFrye_onDeck over 5 years
    This happened to me too when I was duplicating projects for a new solution of similar projects. Please note, you can still use the same output folder for your binaries, just not the same intermediate folder.
  • Amit Bhaira
    Amit Bhaira over 5 years
    @Clippy I have encountered the same when I upgraded the visual studio. I literally wanted to cry when I found this solution.
  • user8128167
    user8128167 about 4 years
    To clarify, you need to right-click on your project, go to "Build Dependencies" -> "Project Dependencies"
  • Juan Pablo
    Juan Pablo about 2 years
    My project was missing many <files>.lib "LINK : fatal error LNK1181: cannot open input file <file>.lib"