简体   繁体   中英

Fatal error LNK1104: cannot open file 'gdi32.lib'

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.

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.

If anyone has this problem on Visual Studio 2017, it is an issue with the Windows 10 Creators Update.

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.

https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#KINativeDesktopWorkload

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

Here is how:

  1. In Visual Studio, go to project properties:

在此输入图像描述

  1. Choose an installed SDK version:

在此输入图像描述

Reference: the developer community for VS

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

It may be a good idea to install the Visual Studia 2015 Update 1 RC too.

It worked for me...

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:

在此输入图像描述

Then go to the Input tab (below on the General tab).

Double Click or select edit to add gdi32.lib:

在此输入图像描述

Finally add your "gdi32.lib" and click OK .

在此输入图像描述

By the way, in Visual Studio 2013 ultimate edition, by default it has gdi32.lib.

I hope it solves your problem.

If you have moved the code from another computer, it may be using the wrong SDK on your platform. Check project Properties → GeneralWindows SDK Version and set it to something shown in the list.

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.

I was trying to compile the CUDA sample project.

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.

To solve it you will need to locate a folder containing the gdi32.lib file.

For my system I found it in 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 ProjectProperties then VC++ directories. Add the path at the top.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM