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

I have been encountering a strange error for some time in Visual Studio 2010.

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

Sometimes, in recent days, very often, after restoring a solution or just compiling it with 1-3 modified 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 the compilation of thelibrary.lib was successful without any errors or warnings.

I tried to clear the solution, but this does not always work.

  • What is wrong here?
+71
c ++ compiler-construction visual-studio
Jun 23 2018-11-11T00:
source share
17 answers

In Linker, general, additional library directories, add the directory to the DLL or .lib that you included in Linker, Input. This does not work if you put it in VC ++ directories, library directories.

+38
Jun 25 2018-12-12T00:
source share

Switch to:

 Project properties -> Linker -> General -> Link Library Dependencies set No. 
+11
May 29 '12 at 11:50
source share

I see only 1 things happening here: you have not properly installed thelibrary.lib dependencies in your project, which means that thelibrary.lib is built in the wrong order (or at the same time, if you have more than 1 CPU assembly configuration, which can also explain the randomness of the error), (you can change the project dependencies in: Menu-> Project-> Project Dependencies)

+9
Jun 23 2018-11-11T00:
source share

I recently got the same error. Some digging caused this: http://support.microsoft.com/kb/815645

Basically, if you have spaces in the .lib path, this is bad. I do not know what is happening to you, but it seems reasonable.

Correction: either 1) put the link to lib in quotation marks, or 2) add the lib path to your library directories (Configuration Properties β†’ VC ++ Directories).

+7
Nov 11 '11 at 13:05
source share

I had the same problem in both VS 2010 and VS 2012. The first static library was created on my system and then immediately deleted when the main project started.

The problem is the shared staging folder for several projects. Just assign a separate staging folder for each project.

Read more about it here.

+4
Sep 29 '13 at 10:50 on
source share

I had a similar problem since I was getting LINK1181 errors in a .OBJ file that was part of the project itself (and there were only 2 .cxx files in the whole project).

First, I installed the project for creating .EXE in Visual Studio, and then in Property Pages -> Configuration Properties -> General -> Project Defaults -> Configuration Type , I changed .EXE to .DLL. Suspecting that Visual Studio 2008 was somehow confused, I recreated the whole solution from scratch using the .DLL mode from the very beginning. After that, the problem disappeared. I assume that if you manually navigate your path through .vcproj and other related files, you can figure out how to fix the situation without starting from scratch (but my program consisted of two .cpp files, so it was easier to start all over again).

+2
Oct 07
source share

I solved this with the following:

Go to View-> Property Pages β†’ Configuration Properties β†’ Connector β†’ Login

In additional dependencies add thelibrary.lib. Do not use any quotes.

+2
Feb 07 '13 at 3:08
source share

I am facing the same question. For me, this is apparently due to the presence of two projects with the same name, one of which depends on the other.

For example, I have one project called Foo that creates Foo.lib. Then I have another project, also called Foo, that creates Foo.exe and links in Foo.lib.

I looked at file activity with Process Monitor. It seems that Foo (lib) is created first - which is correct because Foo (exe) is marked as dependent on Foo (lib). All this is beautifully and successfully built and placed in the output directory - $ (OutDir) $ (TargetName) $ (TargetExt). Then Foo (exe) is started for recovery. Well, remodeling is clean, followed by assembly. It appears that the β€œclean” phase of Foo.exe removes Foo.lib from the output directory. This also explains why the subsequent build build does not delete the output files.

The error is in VS, I think.

Unfortunately, I do not have a solution to the problem, since it includes Rebuild. The workaround is to manually clean Clean and then Build.

+1
Apr 25 '13 at 5:26
source share

I don’t know why, but by changing Linker-> Input-> Additional Dependencies from "dxguid.lib" to "C: \ Program Files (x86) \ Microsoft DirectX SDK (June 2010) \ Lib \ x86 \ dxguid.lib" ( in my case) is the only thing that worked.

+1
Dec 03 '13 at 7:56
source share

For me, the problem was the wrong include directory. I have no idea why this caused an error with the seemingly missing lib library, since the include directory contains only header files. And the library directory had the correct set of paths.

+1
Oct 17 '14 at 12:54 on
source share

You may have hardware problems.

I had the same problem on my old system (AMD 1800 MHz processor, 1 GB RAM, Windows 7 Ultimate) until I changed 2x 512 MB RAM to 2x 1 GB RAM . There have been no problems since. Other (minor) problems also disappeared. Guess that these two 512 MB modules didn’t really like each other because 2x 512 MB + 1 GB or 1x 512 MB + 2x 1 GB did not work either.

0
Jun 24 2018-11-11T00:
source share

You can also fix the problem of a space in the path by specifying the library path in DOS format "8.3".

To get form 8.3, execute (at the command line):

 DIR /AD /X 

recursively through each directory level.

0
Jun 04 '16 at 22:15
source share

I had the same problem. Solved it by specifying an OBJECTS macro containing all the linker objects, for example:

 OBJECTS = target.exe kernel32.lib mylib.lib (etc) 

And then specify $(OBJECTS) on the linker command line.

I do not use Visual Studio though, just nmake and .MAK file

0
Nov 04 '17 at 16:47
source share

I had the same error when starting lib.exe from cmd on Windows with a long list of arguments. obviously cmd.exe has a maximum line length of about 8 KB characters, as a result of which the file names at the end of this threshold were changed, resulting in an error in the file name. My decision was to cut the line. I removed all the paths from the file names and added one path using the / LIBPATH option. eg:

 /LIBPATH:absolute_path /OUT:outfilename filename1.obj filename2.obj ... filenameN.obj 
0
Nov 01 '18 at 2:31 on
source share

I found another solution for this ...

In fact, I missed the comma separator between the two library paths. After adding the general, it worked for me.

Go to: Project properties β†’ Linker β†’ General β†’ Link Library Dependencies On this path, make sure that the library path is correct.

The previous code ( with an error - because I forgot to separate the two lib paths with a comma):

 <Link><AdditionalLibraryDirectories>..\..\Build\lib\$(Configuration)**..\..\Build\Release;**%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> 

Code after fixing (just separate the libraries with commas):

 <Link><AdditionalLibraryDirectories>..\..\Build\lib\$(Configuration)**;..\..\Build\Release;**%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> 

Hope this helps you.

0
May 08 '19 at 11:32
source share

In my case, I had a library installed using the NuGet package (cpprestsdk), and I mistakenly added the library to additional dependencies in the linker settings. It turns out the package does all this for you.

Then the linker tried to find the library on the way to the library and, of course, could not find it.

After removing the library from additional dependencies, everything compiled and linked normally.

0
May 10 '19 at 11:35
source share

I created the bin directory at the project_dir level, and then created the release/debug directory inside the bin folder, which solved the problem for me.

-2
Aug 19 '13 at 17:11
source share



All Articles