32

I've been getting this error ever since I installed the .NET Framework SDK for 64-bit programming on my Visual C++ 2010 Express compiler. I can't compile even a simple program at all because of this single error I'm getting. My platform is x86. Here is a snap shot if it helps:

enter image description here

I don't know what more to say. I just downloaded this compiler yesterday and it was working fine. I wanted to upgrade from 32-bit programming to 64-bit so I could work with Assembly, so I downloaded this SDK. I searched on Google and even here on Stackoverflow. Google didn't help much, but I found a post here that seemed similar to mine but the answers didn't do much justice. Does anyone know why this error is occurring and how I can get rid of it?

Community
  • 1
  • 1
David G
  • 94,763
  • 41
  • 167
  • 253
  • 2
    I'd try this: First search your Program Files directory to see where kernel32.lib is installed, then check the Library Directories listed in your project's VC++ Directories property page and verify that the paths are correct. – Michael Liu Feb 24 '13 at 15:49
  • This was triggered by path mix-ups between multiple SDK installations for my VS2017 installation. I used the VS2017 installer to remove all Win10 SDKs and Toolsets (140 and 141), updated my installation, then re-installed them via the VS2017 installer. After that, problem solved. – kayleeFrye_onDeck May 18 '17 at 01:05

13 Answers13

19

Check the VC++ directories, in VS 2010 these can be found in your project properties. Check whether $(WindowsSdkDir)\lib is included in the directories list, if not, manually add it. If you're building for X64 platform, you should select X64 from the “Platform” ComboBox, and make sure that $(WindowsSdkDir)\lib\x64 is included in the directories list.

Community
  • 1
  • 1
Zaid Amir
  • 4,727
  • 6
  • 52
  • 101
  • 1
    There are a lot of directories. How do I know which one to add it to? For example, there's Executable Directories, Include Directories, etc. [Here's a screen shot](http://gyazo.com/2ee0b79d39dcbfde56d6417a4fc9260b). – David G Feb 24 '13 at 16:03
  • You'll probably need to modify all of them. Bin directory of the sdk goes in the executable directories property, the lib directory goes in the library and so on – Zaid Amir Feb 24 '13 at 16:08
  • You added them as an environment variable or a full path??? If its the fOrmer, did you check if that variable was recognised by VS – Zaid Amir Feb 24 '13 at 16:16
  • I simply copy-pasted `$(WindowsSdkDir)\lib` between the semi-colons `;` where I did not see one in the full path. – David G Feb 24 '13 at 16:19
  • 3
    Well, you need to check if that variable exists.. Simply from the vc++ directories windows, click on any value box, you'll notice an drop arrow, click that and select edit. From the new dialog that popped up, expand macros and see if $(WindowsSdkDir) exists and make sure that the path it refers to is valid. I not then you can simply replace $(WindowsSdkDir) mentioned in my answer with the full path of the sdk. – Zaid Amir Feb 24 '13 at 16:27
  • I did that and it says at the bottom: `$(WindowsSdkDir) C:\Program Files\Microscoft SDKs\Windows\v7.0A\ ` – David G Feb 24 '13 at 16:32
  • I rechecked your question, you are building for x64 so you need to add $(WindowsSdkDir)\lib\x64 and \bin\x64 in library and executable directories respectively – Zaid Amir Feb 24 '13 at 16:38
  • The library already has that, but do I need to just add `\bin\x64` in the Executable one? Where do I add it in? – David G Feb 24 '13 at 16:51
  • Try adding $(WindowsSdkDir)\bin\x64 in executable – Zaid Amir Feb 24 '13 at 17:11
  • If one directory has `$(WindowsSdkDir)include` in it, does it mean I don't have to put in `$(WindowsSdkDir)\bin\x64` because they are the same thing?? – David G Feb 24 '13 at 17:15
  • You don't need to modify the include directories, just the executables.... And yes you still need to add references to the x64 directories each in its respective category – Zaid Amir Feb 24 '13 at 17:40
  • I just found out this only works when my platform isn't x64. That is, when I change it from x64 to Active(Win32) my compiler is all right. But I still can't compile with 64-bit as I want. – David G Feb 24 '13 at 17:41
  • Thats because you are not linking to the x64 libraries – Zaid Amir Feb 24 '13 at 17:43
  • Sorry I'm out... Maybe you can try uninstalling and reinstalling the SDK – Zaid Amir Feb 24 '13 at 18:03
  • New development: It seems I downloaded the SDK for Windows 7, but I'm using Windows *XP*. I'm currently uninstalling the current Windows 7 one and I'm looking for a Windows XP version of the install. Hope I get this one right! – David G Mar 09 '13 at 14:01
  • Unless there's a way to fix this for all future projects created without doing this every time, this answer is more of a hack than an answer. – kayleeFrye_onDeck May 18 '17 at 00:22
19

Change the platform toolset to: "Windows7.1SDK" under project properties->configuration properties->general

gero
  • 191
  • 1
  • 2
  • 4
    This worked instantaneously for me. I had (over time) installed a few tools, and when I came back to my VC++ project, it would not compile (missing headers) etc. I started to hand code include paths, that worked, then I hit link errors, then I tried this solution, and as I said, it just worked!! Many thanks. – Edward Aug 11 '14 at 22:39
6

Make sure you have in VC++ directories (Right click project, Click Property Page),

  • Include Directories: $(IncludePath)
  • List item Library Directories: $(LibraryPath)
namar0x0309
  • 2,239
  • 1
  • 15
  • 15
5

For command line (i.e. - makefile) users only:

  1. When you install VC++ Express, it is 32-bit only. So, things go into C:\Program Files (x86).
  2. Then, you decide to upgrade to 64-bit capabillities. So, you install the SDK. But it is 64-bit capable. So, things go into C:\Program Files.

You (like me) probably "tuned" your makefile to #1, above, via something like this:

MS_SDK_BASE_DOS := C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A
ENV_SET         := LIB="$(MS_SDK_BASE_DOS)\Lib\x64"

But, now, you need to change that tuning to #2, above, like this:

MS_SDK_BASE_DOS := C:\Program Files\Microsoft SDKs\Windows\v7.1

(Don't miss the "v7.0A" to "v7.1" change, as well.)

dbanas
  • 1,707
  • 14
  • 24
3

Add lib path of WindowsSdks in project->properties->Configuration Properties->VC++ Directories -> Library directories.

I added following path and error goes::

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib;

My system is Win-7, 64bit, VS 2013, .net framework 4.5

Ujjaval Moradiya
  • 222
  • 1
  • 12
2

I got a similar error, the problem stopped when I checked my "Linker -> Input -> Additional Dependencies" list in the project properties. I was missing a semi colon ";" just before "%(AdditionalDependencies)". I also had the same entry in twice. You should edit this list separately for Debug and Release.

  • + vote for reminding me that settings change when switching from debug to release, or Win32 to x64. Bah, this project I'm working on his a lot of pre-reqs set before you can do anything, and I made a bonehead mistake and forgot to switch to the correct configuration before tweaking all the values... – kayleeFrye_onDeck Feb 10 '15 at 01:12
2

I had a differnt problem on Windows 10 with Visual Studio 2017 but with the same effects. I think my problems came down to VS being installed onto a drive other than "C:\". I solved the problem by Reinstalling Windows 10 SDK

First I had to uninstall the Windows SDK (there were two versions installed). Then ran the executable. Once installed, ran visual studio and it worked fine.

Malcor
  • 2,667
  • 21
  • 29
1

I just met and solved this problem by myself. My problem is a little different. I'm using visual studio on Windows 10. When I create the project, the Target Platform Version was automatically set to 10.0.15063.0. But there is no kernel32.lib for this version of SDK, neither are other necessary header files and lib files. So I modified the Target Platform Version to 8.1. And it worked.

Environment:

  • Windows 10
  • Visual Studio 2015
  • Visual C++

Solution:

  1. Open the project's Property Page;
  2. Navigate to General page;
  3. Modify Target Platform Version to the desired target platform (e.g. 8.1).
Cosmo
  • 836
  • 1
  • 12
  • 27
0

enter image description here

gero's solution worked for me.
In Visual Studios 2012, take the following steps.
- Go to Solution Explorer
- Right click on your project
- Go to Properties
- Configuration Properties -> General
- Platform Toolset -> change to Windows7.1SDK

Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
0

If the above solution doesn't work, check to see if you have $(LibraryPath) in Properties->VC++ Directories->Library Directories. If you are missing it, try adding it.

0

OS : Win10, Visual Studio 2015

Solution : Go to control panel ---> uninstall program ---MSvisual studio ----> change ---->organize = repair

and repair it. Note that you must connect to internet until repairing finish.

Good luck.

sa1
  • 55
  • 8
0

Today in Visual Studio 2017 I had the same problem.

The cause in my case turned out to be a bad environment setting in NETFXSDKDir (NETFXSDKDir=C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1). It needs to be instead NETFXSDKDir=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x86. Specifically, as set in this batch file (my directory actually has 4 different files) for the Command Prompt for VS2017:

%comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars32.bat"

as I am reluctant to change one of the "as installed" batch files… even more as that batch file calls another yet another:

@call "%~dp0vcvarsall.bat" x86 %*

...instead for my specific C++ command-line app, I simply added the explicit path text: ;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x86 for a total string in "Library Directories" like this: $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x86. (Right click on project, Properties → Configuration Properties → VC++ Directories → Library Directories.) That resolved my "fatal error LNK1104: cannot open file 'kernel32.lib'" error. I found that hint in this GitHub issue.

Note this is reproducible in Visual Studio 2017 Enterprise 2017 Version 15.1 (26403.0) even after successful "repair" install… when creating a new Visual C++ Win32 Console Application and attempting to compile.

In fact, unless a blank application is created, the default template also includes reference to <SDKDDKVer.h> and with that I get this additional error: Error (active) E1696 cannot open source file "SDKDDKVer.h". So I created an empty C++ project.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
gojimmypi
  • 426
  • 4
  • 7
0

In Visual Studio 2017, I went to Project Properties -> Configuration Properties -> General, Selected All Platforms (1), then chose the dropdown (2) under Windows SDK Version and updated from 10.0.14393.0 to one that was installed (3). For me, that was 10.0.15063.0.

enter image description here

Additional details: This corrected the error in my case because Windows SDK Version helps VS select the correct paths. VC++ Directories -> Library Directories -> Edit -> Macros -> shows that macro $(WindowsSDK_LibraryPath_x86) has a path with the version number selected above.

SunsetQuest
  • 8,041
  • 2
  • 47
  • 42