I was a happy man until a few hours back when I was playing with some C, C++ programs built using Visual Studio 2008 on my work and home machines. I could write some program on my workstation, copy the solution to my personal laptop at home and thereby continue from where I left in office. Things were good until I installed the latest Windows SDK v6.1 on my Vista laptop while trying my hands on Windows PowerShell.
I realized a day or so later after installing SDK v6.1 that now I could not build my application written in C or C++. I could compile it but not link it during build process from within Visual Studio. Funny though I realized I could not even build a very basic Win32 console application.
I started getting the following error:
fatal error LNK1181: cannot open input file 'kernel32.lib'
I did something while troubleshooting it and now also started seeing:
Error spawning 'rc.exe'. Project myProject
I did check on the Internet and found all sorts of reasoning around this. One thing looked clear that installing the latest SDK v6.1 had caused me all these headaches. Some links suggested rebooting the server, some talked about low system memory, some said remove the latest SDK v6.1, and some also suggested to reinstall Visual Studio. But somehow I felt this can be fixed without reinstallation of VS2008 or un-installation of SDK v6.1 or etc etc and etc.
I opened the cool Process Monitor tool and found the following:
It was crystal clear that while trying to link Visual Studio was encountering a file not found kind of error and hence could be the resulting failure.
------ Build started: Project: aa, Configuration: Debug Win32 ------
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
Build log was saved at "file://xxxxxxxxxxx\Visual Studio 2008\Projects\myProject\myProject\Debug\BuildLog.htm"
myProject - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Similarly rc.exe showed NOT FOUND.
It looked simple yet intriguing as to why the default path was changed for Visual Studio.
I realized that the path it was trying to look at for these files did not even exist, lest I could just have copied these files to the corresponding location.
Looked at the Environment variables from Visual Studio 2008 command prompt and found that WindowsSdkDir environment variable was pointing to D:\Program Files\Microsoft SDKs\Windows\v6.1\ which did not exist.
Tried changing this to the path where I did find the above files on my box which was pointing to C:\program files\microsoft sdks\windows\v6.0A\ (So yes it pretty much looked like after installing SDK v6.1 my environment variable WindowsSdkDir had changed). Tried logging off/rebooting, no luck.
Finally figured out that in order to get things back to normal I had to update the following registry key:
I changed this value to point to the original location which was C:\Program Files\Microsoft SDKs\Windows\v6.0A\ in my case.
I wasted a lot of time on this, so thought of sharing with a wider audience.