C++ Visual Studio:链接:致命错误 LNK1181:无法打开输入文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6451324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 20:10:03  来源:igfitidea点击:

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

c++visual-studiocompiler-construction

提问by Komn

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

一段时间以来,我一直在 Visual Studio 2010 中遇到一个奇怪的错误。

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:

有时,在最后几天非常频繁,在重建解决方案或仅使用 1-3 个更改的源文件编译后,我收到以下错误:

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

Where compiling thelibrary.libwas a success without any errors or warnings.

thelibrary.lib没有任何错误或警告的情况下编译成功。

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

我试过清洁溶液,但这并不总是有效。

  • What is wrong here?
  • 这里有什么问题?

回答by Chris Thorne

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.

在链接器,一般,附加库目录中,将该目录添加到您在链接器,输入中包含的 .dll 或 .libs 中。如果你把它放在 VC++ 目录、库目录中,它就不起作用。

回答by Sasha

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 )

我只能看到这里发生了 1 件事:您没有在项目中正确设置对 thelibrary.lib 的依赖,这意味着 thelibrary.lib 的构建顺序错误(或者如果您有 1 个以上的 CPU 构建配置,则同时构建,这也可以解释错误的随机性)。(您可以在以下位置更改项目依赖项: Menu->Project->Project Dependencies )

回答by EkaYuda

Go to:

去:

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

回答by Clippy

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

我最近遇到了同样的错误。一些挖掘提出了这个: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.

基本上,如果 .lib 的路径中有空格,那就不好了。不知道这是否是您正在发生的事情,但似乎是合理的。

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).

修复方法是 1) 将 lib 引用放在“引用”中,或 2) 将 lib 的路径添加到您的库目录(配置属性 >> VC++ 目录)。

回答by alexkr

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.

我在 VS 2010 和 VS 2012 中都遇到了同样的问题。在我的系统上,第一个静态库被构建,然后在主项目开始构建时被立即删除。

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

问题是几个项目的公共中间文件夹。只需为每个项目分配单独的中间文件夹。

Read more on this here

此处阅读更多相关信息

回答by user2049230

I solved it with the following:

我用以下方法解决了它:

Go to View-> Property Pages -> Configuration Properties -> Linker -> Input

转到查看-> 属性页-> 配置属性-> 链接器-> 输入

Under additional dependencies add the thelibrary.lib. Don't use any quotations.

在附加依赖项下添加 thelibrary.lib。不要使用任何引号。

回答by Nick

I'm stumbling into the same issue. For me it seems to be caused by having 2 projects with the same name, one depending on the other.

我遇到了同样的问题。对我来说,这似乎是由 2 个同名的项目引起的,一个取决于另一个。

For example, I have one project named Foo which produces Foo.lib. I then have another project that's also named Foo which produces Foo.exe and links in Foo.lib.

例如,我有一个名为 Foo 的项目,它生成 Foo.lib。然后我有另一个项目,它也被命名为 Foo,它在 Foo.lib 中生成 Foo.exe 和链接。

I watched the file activity w/ Process Monitor. What seems to be happening is Foo(lib) is built first--which is proper because Foo(exe) is marked as depending on Foo(lib). This is all fine and builds successfully, and is placed in the output directory--$(OutDir)$(TargetName)$(TargetExt). Then Foo(exe) is triggered to rebuild. Well, a rebuild is a clean followed by a build. It seems like the 'clean' stage of Foo.exe is deleting Foo.lib from the output directory. This also explains why a subsequent 'build' works--that doesn't delete output files.

我观看了带有进程监视器的文件活动。似乎正在发生的是 Foo(lib) 首先构建——这是正确的,因为 Foo(exe) 被标记为依赖于 Foo(lib)。这一切都很好并且构建成功,并放置在输出目录中--$(OutDir)$(TargetName)$(TargetExt)。然后触发 Foo(exe) 重建。好吧,重建是清理,然后是构建。似乎 Foo.exe 的“干净”阶段正在从输出目录中删除 Foo.lib。这也解释了为什么后续的“构建”有效——不会删除输出文件。

A bug in VS I guess.

我猜是 VS 中的一个错误。

Unfortunately I don't have a solution to the problem as it involves Rebuild. A workaround is to manually issue Clean, and then Build.

不幸的是,我没有解决问题的方法,因为它涉及重建。一种解决方法是手动发出 Clean,然后再发出 Build。

回答by user1726157

I had a similar problem in that I was getting LINK1181errors on the .OBJfile that was part of the project itself (and there were only 2 .cxx files in the entire project).

我有一个类似的问题,因为我在作为项目本身一部分LINK1181.OBJ文件中遇到错误(整个项目中只有 2 个 .cxx 文件)。

Initially I had setup the project to generate an .EXEin Visual Studio, and then in the Property Pages -> Configuration Properties -> General -> Project Defaults -> Configuration Type, I changed the .EXE to .DLL. Suspecting that somehow Visual Studio 2008 was getting confused, I recreated the entire solution from scratch using .DLL mode right from the start. Problem went away after that. I imagine if you manually picked your way through the .vcproj and other related files you could figure out how to fix things without starting from scratch (but my program consisted of two .cpp files so it was easier to start over).

最初我设置了项目以.EXE在 Visual Studio 中生成一个,然后在 Property Pages -> Configuration Properties -> General -> Project Defaults -> Configuration Type.EXE 中更改为 .DLL。怀疑不知何故 Visual Studio 2008 变得混乱,我从一开始就使用 .DLL 模式从头开始重新创建整个解决方案。之后问题就迎刃而解了。我想如果您手动选择 .vcproj 和其他相关文件,您可以弄清楚如何解决问题而无需从头开始(但我的程序由两个 .cpp 文件组成,因此更容易重新开始)。

回答by Vic

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

我不知道为什么,但是将 Linker->Input->Additional Dependencies 引用从“dxguid.lib”更改为“C:\Program Files (x86)\Microsoft DirectX SDK(2010 年 6 月)\Lib\x86\dxguid。 lib”(就我而言)是唯一有效的方法。

回答by mgttlinger

For me the problem was a wrong includedirectory. I have no idea why this caused the error with the seemingly missing lib as the include directory only contains the header files. And the library directory had the correct path set.

对我来说,问题是一个错误的include目录。我不知道为什么这会导致看似缺少 lib 的错误,因为包含目录仅包含头文件。并且库目录设置了正确的路径。