Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link Errors in Unmodified Visual Studio 2012 MFC Template when Statically Linking MFC

When creating a new MFC application of the simplest kind in Visual Studio 2012, and setting it to link statically to MFC, linking fails.

Here's a gallery of 7 screenshots starting from the creation of the project via the wizard, up to the building (resulting in the linker error). No source editing was done in-between.

The error logs state:

1>------ Build started: Project: Test, Configuration: Debug Win32 ------
1>  stdafx.cpp
1>  TestDlg.cpp
1>  Test.cpp
1>  Generating Code...
1>uafxcwd.lib(afxctrlcontainer2.obj) : error LNK2005: "void __cdecl AfxRegisterMFCCtrlClasses(void)" (?AfxRegisterMFCCtrlClasses@@YAXXZ) already defined in afxnmcdd.lib(afxctrlcontainer2.obj)
1>uafxcwd.lib(afxctrlcontainer2.obj) : error LNK2005: "protected: void __thiscall CMFCControlContainer::PreUnsubclassControl(class CWnd *)" (?PreUnsubclassControl@CMFCControlContainer@@IAEXPAVCWnd@@@Z) already defined in afxnmcdd.lib(afxctrlcontainer2.obj)
1>uafxcwd.lib(afxctrlcontainer2.obj) : error LNK2005: "public: int __thiscall CMFCControlContainer::SubclassDlgControls(void)" (?SubclassDlgControls@CMFCControlContainer@@QAEHXZ) already defined in afxnmcdd.lib(afxctrlcontainer2.obj)
1>C:\Users\XXXXXXXX\Documents\Visual Studio 2012\Projects\Test\Debug\Test.exe : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Is this just me? Would you have a suggestion on how to address this?

like image 217
Paul Avatar asked Nov 27 '12 17:11

Paul


2 Answers

I got the same problem when I try static link my project together.

As Michael Burr suggested, it seems fine after commented out the line of #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS in stdafx.h.

like image 117
Mark Guo Avatar answered Sep 17 '22 15:09

Mark Guo


I've come across the same issue. If you decide to #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS and get rid of a lot MFC overhead you should also be sure you change the dialog base classes, method calls,etc from CDialogEx to CDialog.

If you don't change the background color or the image of your dialog, you will find that CDialogEx is pretty useless anyway.

like image 35
gmanolache Avatar answered Sep 18 '22 15:09

gmanolache