13

I have installed VS2013 and VS2015 on Windows 7.

I have an existing C++ Dll project that was building fine but now all of a sudden it wont build using VS2015 and gives me the error:

LINK : fatal error LNK1104: cannot open file 'kernel32.lib'

From this post: fatal error LNK1104: cannot open file 'kernel32.lib' I went looking for the kernel32.lib file and it is located here:

C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86

When I go to my Projects Properties-->Linker-->Input and select Macros I see that this path is indeed there:

enter image description here

My Platform Toolset is set to Visual Studio 2013 - Windows XP (v120_xp) which is what it always has been set to.

Why has my Project all of a sudden stopped building? What could have gone wrong?

Community
  • 1
  • 1
Harry Boy
  • 4,159
  • 17
  • 71
  • 122
  • 1
    See if my answer http://stackoverflow.com/a/39472273/383779 can help in some way. Check your props files. – sergiol Sep 15 '16 at 15:16
  • This solved it my friend thanks so much :) – Harry Boy Sep 15 '16 at 15:27
  • 1
    No one's solutions were working for me for this or similar answers, for VS2017. My solution ended up being uninstalling my Win10 SDKs and v140 and v141 toolsets via the 2017 installer, then re-installed them. Problem solved. – kayleeFrye_onDeck May 18 '17 at 00:55

9 Answers9

7

I had this similar problem today with Visual Studio 2013 when I changed my VC++ Directories:

Project->Properties->VC++ Directories: Include Directories

João Luis
  • 71
  • 1
  • 1
3

If the cause is some plug-in/extension that changes your props files, it may in consequence change the "Visual C++ Directories" settings of your project.

So, the solution that worked for me is described on my own answer Can't compile 64 bits Visual Studio 2010 projects, which I fully transcribe to here:

After I asked a colleague for help, we noticed, that even getting clean builds of the projects from TFS, with overwrite option, the Project's Configuration Properties > VC++ Directories on my computer were always different from other computers.

Searching more we found the solution on the last post of Reset include/lib path, which I will fully transcribe:

use "del %HOMEPATH%\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props" is not always the right way. Better use "del %USERPROFILE%\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props" where the application data folder is normally placed in.

Then I've looked inside the contents of Microsoft.Cpp.x64.user.props and I've seen that there were things added by Visual Leaks Detector. Which is reasonable, as one month before, I did a memory leak analysis using VLD.

So, I deleted the file and now everything compiles fine at 64bits!

Community
  • 1
  • 1
sergiol
  • 4,122
  • 4
  • 47
  • 81
3

I had to install the Visual C++ for Desktop Development.

Open Visual Studio Installer and go to Installed tab. Click on the Change Button on your installed Visual Studio Community Edition. -> On the Workloads Tab there should be a option Desktop Development with C++. Activate that option and modify the changes.

Afterwards it was working for me.

Marcel R
  • 51
  • 4
2

I got this error fatal error lnk1104: cannot open file 'kernel32.lib'. this error is getting because there is no path in VC++ directories. To solve this probelem

  1. open visual studio 2008
  2. go to Tools-options-Projects and Solutions-VC++ directories-*
  3. then at right corner select Library files
  4. here you need to add path of kernel132.lib

In my case It is C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib

Thank you.

2

In VS 2022 I was trying to compile an old solution that originally ran in VS 2010 then in VS 2019. It continually gave me the "cannot find Kernel32.lib" error. I spent 8 hours trying everything, including everything on this page. What worked for me: Configuration Properties -> VC++ Directories -> Library Directories and "inherit from parent" (guessing this sets to defaults) fixed this for me. Also note: I'm using winsock and directinput.

rar76
  • 21
  • 1
1

I had the same problem today. As it turned out somehow the SDK 10.0.15063.0 got installed on my system but without the Desktop C++ files. Selecting the SDK in the list of installed programs, doing a change install and there selecting the Desktop C++ options added the necessary files and now I can link again.

Werner Henze
  • 16,404
  • 12
  • 44
  • 69
1

I had this following upgrade of some projects from VS2013 to VS2017.

Original project had a manual modification to the "Library Directories" item under VC++ Directories in the project settings.
This meant it did not pick up changes from the upgrade.

Using the option will reset this to something that works (assuming the SDK is installed OK) provided anything other than the default is not needed of course. In my case it was trying to point at the v7.1 SDK but that was not installed for vs2017.

Pete
  • 4,784
  • 26
  • 33
1

in vs 2019, just run the installer, click modify, and then in the individual components tab, remove windows 10 SDK. then again run the installer and add windows 10 sdk!

0

I had this similar problem today with Visual Studio 2017. My cause turned out to be a bad environment setting in NETFXSDKDir, specifically:

NETFXSDKDir=C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1

It needed to have a value of:

C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x86

I have a more detailed response here:

fatal error LNK1104: cannot open file 'kernel32.lib'

Community
  • 1
  • 1
gojimmypi
  • 426
  • 4
  • 7