Visual C 中的链接错误 LNK1104 2010年
今天,我启动了 Visual Studio 2010 (Visual C++) 并开始处理一个项目。该解决方案包含两个项目。一个是我正在编写的静态库,另一个是包含该库的单元测试的测试应用程序。
在不改变昨天的任何内容的情况下,可执行文件不再链接:
LINK : fatal error LNK1104: cannot open file 'mylib.lib'
静态库可以正常编译和链接。我大约一周没有更改项目设置,昨天链接得很好。
如果我进入可执行项目的设置并添加 $(SolutionDir)\debug
的库目录,则会收到以下链接错误:
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
我不确定问题是什么。我尝试过清理、重建,甚至重新启动我的机器。 Google 在古老的 Visual C++ 版本中发现了一些错误(但我使用的是 2010),并且该程序可能已经在运行。但是,它没有运行,并且重新启动证实了这一点。
什么会导致链接器找不到 kernel32.lib 等核心库,或者我的解决方案的输出目录?
这是老式的 C++,一个跨平台库,而不是微软添加的托管东西。
Today I fired up Visual Studio 2010 (Visual C++) and started working on a project. The solution contains two projects. One is a static library I am writing, the other is a test application containing unit tests for the library.
Without changing anything from yesterday, the executable no longer links:
LINK : fatal error LNK1104: cannot open file 'mylib.lib'
The static library compiles and links fine. I have not changed the project settings in around a week, and it was linking just fine yesterday.
If I go into the executable project's settings and add a library directory for $(SolutionDir)\debug
, I instead get the following link error:
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
I am not sure what the problem is. I have tried cleaning, rebuilding, and even rebooting my machine. Google turned up some bugs in ancient Visual C++ versions (but I'm using 2010), as well as the possibility that the program is already running. However, it is not running, and a reboot confirms this.
What would cause the linker not to find core libraries such as kernel32.lib, or for that matter, the output directory for my solution?
This is old-fashioned C++, a cross-platform library, not that managed stuff Microsoft added.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我必须在“库目录”对话框中选中“从父级或项目默认值继承”。一旦我这样做了,链接器就可以找到所有必需的库。不过,我仍然必须包含
$(SolutionDir)\debug
。I had to check "Inherit from parent or project defaults" in the "Library Directories" dialog. Once I did that, the linker could find all the necessary libraries. I still had to include
$(SolutionDir)\debug
though.在项目->属性->链接器->常规->附加库目录中包含microsoft SDK目录。
在我的计算机上它是
D:\Program Files\Microsoft SDKs\Windows\v7.1\Lib
Include the microsoft SDK directory in project->properties->linker->general->additional library directories.
on my computer it is
D:\Program Files\Microsoft SDKs\Windows\v7.1\Lib
我通过禁用“启用.NET Framework源代码步进”解决了这个问题(请参阅:“菜单栏/工具/选项/调试/常规/启用.NET Framework源代码步进”)。显然 这是 Visual 中的错误工作室。
I fixed this problem by disabling "Enable .NET Framework source stepping" (see: "Menu bar / Tools / Options / Debugging / General / Enable .NET Framework source stepping"). Apparently this is a bug in Visual Studio.