由于链接器无法找到同名的 .lib 文件,因此无法构建 Dll 项目

发布于 2024-11-19 04:20:59 字数 274 浏览 3 评论 0原文

我是 Visual Studio 2010 环境的新手。我得到了一个使用 Visual Studio 2008 开发的源代码库。我正在尝试在 VS 2010 中构建它;但构建失败,因为链接器显示错误 - LINK:致命错误 LNK1181:无法打开输入文件 X.lib'。

这里 X 是从同一项目创建的 lib 文件的名称,X.dll 是输出 dll。事实上,X.lib 并不存在于项目中。如果没有成功构建项目,Dll 就根本无法成功构建。如何解决这种“僵局”的情况?

预先感谢,

石朱

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唯憾梦倾城 2024-11-26 04:20:59

我也有这个问题。将正在运行的 VS2008 项目转换为 VS2010 时,VS2010 项目中的链接阶段会中断,并出现相同的错误。它正在尝试链接该项目应该构建的 .lib!

我找到了问题的根源:该项目有一个自定义构建步骤,该步骤发生在构建结束时、PostBuildEvent 之前。此自定义构建步骤将 .dll、.lib 和 .pdb 从 $(OutDir) 复制到外部位置。

自定义构建步骤的输出列表设置为复制的 .dll、.lib 和 .pdb 的完整路径,例如:

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

我发现每当此输出列表包含 .lib 时,该 .lib 就会添加到文件列表中链接阶段的链接。因此,对于上面的输出列表,链接阶段将具有以下文件列表:

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

这会导致链接失败:

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

自定义构建步骤中的副本是否实际复制文件并不重要。重要的是输出列表包含 .lib。因此,当然,我通过从输出列表中删除 .lib 解决了这个问题。这样做的缺点是执行 Clean 构建不会清理 C:/a_new_location/lib。但至少它建立了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文