I am refactoring a big legacy project. It used to link libraries within its source files via #pragma comment(lib, "lib_name.lib").
Once I've moved #pragma comment(lib, "mmc.lib") from the .cpp file to .vcxproj, I started receiving multiple definitions linker error:
1>uafxcwd.lib(afxstate.obj) : error LNK2005: "public: __cdecl AFX_MAINTAIN_STATE2::~AFX_MAINTAIN_STATE2(void)" (??1AFX_MAINTAIN_STATE2@@QEAA@XZ) already defined in mmc.lib(apimfc.obj)
I couldn't find the unit which caused multiple definitions since it is generated by a macro AFX_MANAGE_STATE (which by itself was very hard to determine). Basically, I had to rebuild the project, each time incrementally adding units and uncommenting the code.
I thought that some header is to blame, but it happened to be not the case. I have stripped the project to a single .cpp file:
#include <afx.h>
#include <Windows.h>
struct SINODE;
struct IConsole;
// some .cpp file
HRESULT OnAlertsSettings(SINODE * lpNode, LPVOID lpParam, IConsole * lpConsole)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()); // this exact line causes multiple definitions
reurn S_OK;
}
Linker: mmc.lib
How can I fix this?