2
votes

I am a newbie in the Visual Studio 2010 environment. I got a source base which was developed using Visual Studio 2008. I am trying to build it in VS 2010; but the build fails as the Linker says the error - LINK : fatal error LNK1181: cannot open input file X.lib'.

Here X is the name of the lib file created from the same project and X.dll is the output dll. In fact the X.lib is not present in the project. Without succesfully building the project, it won't come at all for the Dll to build succesfully. How can I resolve this "Deadlock" kind of situation?

Thanks in advance,

Shiju

1
Your description is not clear. Is X a project that is in your solution along with another project, which uses X? If so, why can't you build only the X project? If not, please further describe the projects in your solution...eran
Hi, project X is in my solution. The solution has another few projects also in it. Project X uses the Dlls generated by the other projects. That part is fine. The problem is that, I made a Clean of the solution and deleted the X.lib file present in the release folder. Later when the project X builds, it is supposed to create X.dll. But it is mentioned to have an input dependency for "X.lib" which is not present in the solution. This X.lib will be created only after a succesful build of the project X right? So I assumed this situation as similar to a "deadlock".Jo Bell

1 Answers

1
votes

I had this problem also. When converting a working VS2008 project to VS2010, the Link phase breaks in the VS2010 project with the same error. It is trying to link the .lib that the project is supposed to be building!

I found the source of my problem: The project has a custom build step that occurs at the end of the build, before the PostBuildEvent. This custom build step copies the .dll, .lib and .pdb from $(OutDir) to an external location.

The Outputs List for the custom build step is set to the full path to the copied .dll, .lib and .pdb, e.g.:

C:/a_new_location/myproject.dll;
C:/a_new_location/myproject.lib;
C:/a_new_location/myproject.pdb.

I found that whenever this Outputs List includes the .lib, that .lib gets added to list of files to link in the link phase. So with the above Outputs List, the link phase will have a file list of:

myprojectfile1.obj
myprojectfile2.obj
C:/a_new_location/myproject.lib

And that causes the link to fail:

LINK : fatal error LNK1181: cannot open input file 'C:\a_new_location\G4SrcCfgLib.lib'

It does not matter if the copy in the custom build step actually copies the file or not. All that matters is that the Outputs List includes the .lib. So, I resolved the problem by removing the .lib from the Outputs List, of course. The downside to this is that doing a Clean build will not clean C:/a_new_location/lib. But at least it builds.