Thursday, March 11, 2010

SmartA$$ Microsoft Compiler adding an 'A' at the end of a method

I just spent 2+ hours trying to fix a 'linker' error reported by Microsoft's coveted Visual Studio 2008 C++ compiler/linker.

An application was linking to a clean library, with the suspect method properly implemented and exposed via the class's public interface. But the linker kept complaining that the method's symbol cannot be found in the library. Not even multiple clean/manual-clean/rebuilds helped.

As the frustration rose, I decided to finally use the dumpbin utility to actually dump the symbols exported by the suspect library. Funnily enough, the symbol I found had the letter 'A' appended to the end of it's name in the lib. Why?? I didn't declare the method with that name?

So I changed the name of the method, and then everything started working perfectly.

The real cause of the problem? Windows system headers already have a macro changing the name of that method based upon whether UNICODE is used or not, and so Microsoft's compiler was changing the name of the method I declared from 'AddJob' to 'AddJobA' before creating the symbols.

But wait: here's the best part: The linker would STILL complain it cannot find the symbols for the 'original' method name, 'AddJob'! So the compiler was smart enough to change the name of the symbol when creating it, but the linker is totally unaware of it.

HAH! So much for a smart software, Microsoft! Shame on you!!!

By the way here is another link I found on the web about the same issue later.

P.S. And of course the community section at Microsoft wont let me add any content to let others know and not repeat this mistake. Ughhhh!!!

12 comments:

Thank you for leaving a comment on my blog. Please feel free to share any information you find relevant here.