Friday 2 September 2011

Debugging issues with MSVCR90.DLL

Keep eye on the linker issue when debugging programs.
When we first migrated our applications from Microsoft Visual C++ 6 to Microsoft Visual Studio 2008, we received the following messages when trying to run our debug builds in the debugger:
This application has failed to start because MSVCR90.dll was not found.  Re-installing the application may fix this problem.
At first, it didn't make sense.  We looked for MSVCR90.dll and it was properly installed in the Side-by-side (SxS) system folders.  Our release version would also run fine and that used the same DLL.
Then it hit me:  why is it looking for MSVCR90.DLL while running debug?  Shouldn't it be looking for MSVCR90D.DLL?
A quick look using Dependency Walker (one of the best developer's utilities ever created) showed me that we were linking to both MSVCR90D.DLL and MSVCR90.DLL.
The solution is to ignore MSVCR90 (and if necessary, MSVCRT) when linking.  This can be done from the project properties:
image
But only do this for the debug configurations.  Once you do this, re-link, and your application should start.  If you continue to get this same error message, then using Dependency Walker again, check that some of your DLLs don't need the same modification.  In addition, if you attempt to do a LoadLibrary() on one of your DLLs and you're getting a cryptic message about the DLL not being found, it may be the same thing.  Use Dependency Walker on that DLL and modify those projects if necessary.
Thinking back, when linking using Visual C++ 6, I remember some linker messages like the following which (at the time) I thought was safe to ignore.
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
Maybe in the good 'ole days, we could ignore such a message.  Today, we're not so lucky.
BTW, Microsoft, please make a better error message for such a situation.

No comments:

Post a Comment