I am getting this linker error.
mfcs80.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in MSVCRT.lib(dllmain.obj)
This can also occur if your solution has multiple projects that export the same symbols. For example if you have sub-project that builds foo.dll
with a foo.def
file that exports DoFoo
and a sub-project for bar.dll
with a bar.def file that exports DoFoo
, a collision will occur and this is the error you will see when you link.
I found this which helped me: http://support.microsoft.com/kb/148652
Basically the linker order was incorrect. the CRT libs were getting linked before the MFC libs. Turns out, the MFC libs had to get linked FIRST, and then the CRT libs could be linked.
Yucko Microsoft!!
For me the direct cause was indeed a missing _afxForceUSRDLL symbol reference, but the indirect cause was a missing _USRDLL macro definition. It is defined by default by the VC wizard, but occasionally devs erase it erroneously. Here it is in more words.
Declare the mfc80ud.lib
and mfcs80ud.lib
in the Additional Dependancies
field in the Project Properties -> Linker Tab -> Input of Visual Studio
to fix the issue.
Just #undef
the _USRDLL
before including afx.h
, or even better, edit your project configuration and remove the macro.
This is the usual configuration for a MFC extension DLL: Build Settings for an MFC DLL
Make sure you include "Stdafx.h" at the top of each .cpp file. I was getting the exact same error and had a single .cpp file that did not include this header at all. Adding the #include solved the problem.