C++ 致命错误 LNK1104:无法打开文件“gdi32.lib”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33599723/
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
Fatal error LNK1104: cannot open file 'gdi32.lib'
提问by JSK
Every time I try to run my code I get this error. I've tried everything, installing the SDK, but I still get the same error.
每次我尝试运行我的代码时,我都会收到此错误。我已经尝试了所有方法,安装了 SDK,但仍然出现相同的错误。
1>------ Build started: Project: ConsoleApplication6, Configuration: Debug Win32 ------
1>LINK : fatal error LNK1104: cannot open file 'gdi32.lib'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I'm using Windows 7 and Visual Studio 2012.
我使用的是 Windows 7 和 Visual Studio 2012。
回答by user7880029
If anyone has this problem on Visual Studio 2017, it is an issue with the Windows 10 Creators Update.
如果有人在 Visual Studio 2017 上遇到此问题,则是 Windows 10 创意者更新的问题。
A workaround is to select the "Windows 10 SDK (10.0.15063.0) for Desktop C++ x86 and x64" under the "Desktop development with C++" workload in the Visual Studio Installer.
解决方法是在 Visual Studio 安装程序中的“使用 C++ 进行桌面开发”工作负载下选择“Windows 10 SDK (10.0.15063.0) for Desktop C++ x86 and x64”。
https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#KINativeDesktopWorkload
https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#KINativeDesktopWorkload
回答by Christian Eriksson
In Visual Studio 2017 (Community edition) I solved this by switching the Windows SDK version in the project properties from 10.0.10586.0 to 10.0.16299.0 (which is the version I've installed on my machine).
在 Visual Studio 2017(社区版)中,我通过将项目属性中的 Windows SDK 版本从 10.0.10586.0 切换到 10.0.16299.0(这是我在我的机器上安装的版本)解决了这个问题。
Here is how:
方法如下:
- In Visual Studio, go to project properties:
- 在 Visual Studio 中,转到项目属性:
- Choose an installed SDK version:
- 选择已安装的 SDK 版本:
Reference: the developer community for VS
参考:VS 开发者社区
回答by Diogyn
For those having the same problem with Visual Studio 2015 on Windows 10, it may be because the installation was broken. If so, just launch the installation program to do "Repair".
对于那些在 Windows 10 上使用 Visual Studio 2015 遇到相同问题的人,可能是因为安装已损坏。如果是这样,只需启动安装程序进行“修复”。
It may be a good idea to install the Visual Studia 2015 Update 1 RC too.
也安装 Visual Studia 2015 Update 1 RC 可能是个好主意。
It worked for me...
它对我有用...
回答by Brian
To solve it you will need to locate a folder containing the gdi32.lib
file.
要解决它,您需要找到一个包含该gdi32.lib
文件的文件夹。
For my system I found it in C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x86
.
对于我的系统,我在C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x86
.
Simply add it into the property sheet for your project. As described in other posts, menu Project→ Propertiesthen VC++ directories. Add the path at the top.
只需将其添加到项目的属性表中即可。如其他帖子所述,菜单项目→属性,然后是 VC++ 目录。在顶部添加路径。
回答by Ahmet Tavli
From what I understand you haven't defined the path of your library.
据我了解,您还没有定义库的路径。
Right click on Project --> Properties
右键单击项目--> 属性
Under Configuration properties, on "Linker" tab, select "General" on "Additional Library Directories". Select the path of gdi32.lib:
在配置属性下的“链接器”选项卡上,选择“附加库目录”上的“常规”。选择gdi32.lib的路径:
Then go to the Inputtab (below on the Generaltab).
然后转到“输入”选项卡(位于“常规”选项卡下方)。
Double Click or select edit to add gdi32.lib:
双击或选择编辑添加 gdi32.lib:
Finally add your "gdi32.lib" and click OK.
最后添加您的“gdi32.lib”并单击OK。
By the way, in Visual Studio 2013 ultimate edition, by default it has gdi32.lib.
顺便说一下,在 Visual Studio 2013 终极版中,默认情况下它有 gdi32.lib。
I hope it solves your problem.
我希望它能解决你的问题。
回答by IllidanS4 wants Monica back
If you have moved the code from another computer, it may be using the wrong SDK on your platform. Check project Properties → General→ Windows SDK Versionand set it to something shown in the list.
如果您从另一台计算机上移动了代码,则它可能在您的平台上使用了错误的 SDK。检查项目属性 →常规→ Windows SDK 版本并将其设置为列表中显示的内容。
回答by Mike Lee
I'm on Windows 8.1 Visual Studio 2017 Professional, and I got it to work after switching the project properties Windows SDK version to 8.1, build, then switch it back to 10.0.16299.0.
我使用的是 Windows 8.1 Visual Studio 2017 Professional,在将项目属性 Windows SDK 版本切换到 8.1、构建,然后将其切换回 10.0.16299.0 后,我让它开始工作。
I was trying to compile the CUDA sample project.
我试图编译 CUDA 示例项目。
It worked, don't ask me why. Maybe it has something to do with me having the Visual Studio Community 2017 and then uninstalling it to install the professional.
成功了,别问我为什么。也许这与我拥有 Visual Studio Community 2017 然后卸载它以安装专业版有关。