Bizarre Build Errors
Have you ever had one problems with a build system that just seems to be inexplicable? I ran into one yesterday that nothing on Google seemed to be able to help with, so I thought I'd post it here in hopes that this might get someone out of a jam in the future. I was compiling some code for a DLL through a Microsoft compiler got these error statements:
This is editied to hide the paths and file names.
C:\somepath\dll.cpp(26) : error C2731: 'DllMain' : function cannot be overloaded
C:\somepath\dll.cpp(25) : see declaration of 'DllMain'
C:\somepath\dll.cpp(26) : error C2733: second C linkage of overloaded function 'DllMain' not allowed
C:\somepath\dll.cpp(25) : see declaration of 'DllMain'
When you look at the file:
24:
25: extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
26: {
27:
So what should one make of this? The { is actually a redeclaration of the function? No, that would be ridiculous (and one might argue appropriately that the compiler should not give back such crazy statements). Perhaps the #defined terms BOOL, WINAPI, or maybe the typedefs were literally mistyped? No, those were triple checked. Is there a library which is being linked in before the compile phase of the file which already defines DllMain? Why didn't the compiler reference that lib then as the source of the definition?
Well it turns out that none of that is true. Instead, the term DllMain is somewhat akin to a keyword now and the compiler secretly gives you a DllMain function, which this declaration then clashes with. If you rename the function and declare the entry point of the DLL (since DllMain is suppose to be the entry) to the new name, everything works. So it goes to show that the compiler isn't acting inexplicably, just secretly (it's not telling you that it included the default function, or where it's from in the error message) and stupidly (it doesn't get rid of the default function, when clearly you want your own).
