25

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
JSK
  • 1,086
  • 3
  • 10
  • 19
  • 1
    Your installation is botched. You can check the project property page for the various directories, in particular the library directory and then verify that the path is valid. – MicroVirus Nov 08 '15 at 22:37

7 Answers7

53

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

user7880029
  • 546
  • 5
  • 2
  • For anyone wondering, yes this is the right solution if you are getting no compiler found error with VS2017 generation after an Win 10 creators update. Thanks for the answer. – Maroš Beťko Apr 25 '17 at 06:56
  • Yes this solution worked for me in VS2017 on Win 10 creators update – Steve Obbayi Apr 26 '17 at 15:27
  • Also note that it has a component for each architecture - "Windows SDK for Desktop C++ [arch] Apps". I had only installed x86 and couldn't work out why 32-bit builds worked, but 64-bit builds gave this error. Installing the amd64 component fixed it. – Timmmm Jul 17 '17 at 12:09
  • I downloaded the Windows 10 SDK (10.0.15063.0) from the link below since my Visual Studio installer did not list through 10.0.15063.0. https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk – Jeff Benshetler Jul 18 '17 at 22:26
9

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:

enter image description here

  1. Choose an installed SDK version:

enter image description here

Reference: the developer community for VS

Christian Eriksson
  • 2,038
  • 2
  • 22
  • 28
  • Despite this answer from (user7880029) being correct. I liked this answer more because it shows what is needed to do ,. Otherwise, I would need to see how to find where to select windows SDK. Thank you for saving me another google search. – LUser Dec 15 '17 at 13:45
6

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

Diogyn
  • 443
  • 4
  • 9
0

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:

Enter image description here

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

Double Click or select edit to add gdi32.lib:

Enter image description here

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

Enter image description here

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

I hope it solves your problem.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ahmet
  • 7,527
  • 3
  • 23
  • 47
  • 7
    All editions of Visual Studio, barring those where the install is broken, have the default library directory set properly in the 'VC++ Directories' page and have the 'gdi32.lib', and related, appear in 'Linker->Input->Additional Dependencies' via inherit from parent. This answer may solve this one particular issue, once, but there is a larger underlying problem that has not been solved this way. – MicroVirus Nov 10 '15 at 11:53
0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
IS4
  • 11,945
  • 2
  • 47
  • 86
0

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.

Mike Lee
  • 2,440
  • 26
  • 12
0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Brian
  • 1