jbx
jbx

Reputation: 22178

Link errors between dialog application and library

I have a dialog application that used to work perfectly. It uses MFC. I wanted to move some of the classes to a separate library (in the same solution), so I created a new project in the same solution, selected Win32 Console App, Static library and MFC and moved the classes to the new project. The library project seems to compile fine.

In the original project I added a reference to the new library.

I am getting these errors now, no idea how to solve them. If I edit the project properties and select Linker/Input/Ignore All Default Libraries I get much more errors.

1>afxnmcdd.lib(wincore2.obj) : error LNK2005: "void __stdcall DDX_Control(class CDataExchange *,int,class CWnd &)" (?DDX_Control@@YGXPAVCDataExchange@@HAAVCWnd@@@Z) already defined in nafxcwd.lib(wincore2.obj)
1>afxnmcdd.lib(wincore2.obj) : error LNK2005: "public: int __thiscall CWnd::ExecuteDlgInit(void *)" (?ExecuteDlgInit@CWnd@@QAEHPAX@Z) already defined in nafxcwd.lib(wincore2.obj)
1>afxnmcdd.lib(afxctrlcontainer2.obj) : error LNK2005: "void __cdecl AfxRegisterMFCCtrlClasses(void)" (?AfxRegisterMFCCtrlClasses@@YAXXZ) already defined in nafxcwd.lib(afxctrlcontainer2.obj)
1>afxnmcdd.lib(afxctrlcontainer2.obj) : error LNK2005: "protected: void __thiscall CMFCControlContainer::PreUnsubclassControl(class CWnd *)" (?PreUnsubclassControl@CMFCControlContainer@@IAEXPAVCWnd@@@Z) already defined in nafxcwd.lib(afxctrlcontainer2.obj)
1>afxnmcdd.lib(afxctrlcontainer2.obj) : error LNK2005: "public: int __thiscall CMFCControlContainer::SubclassDlgControls(void)" (?SubclassDlgControls@CMFCControlContainer@@QAEHXZ) already defined in nafxcwd.lib(afxctrlcontainer2.obj)
1>afxnmcdd.lib(afxctrlcontainer2.obj) : error LNK2005: "public: static int __stdcall CMFCControlContainer::UTF8ToString(char const *,class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > > &,int)" (?UTF8ToString@CMFCControlContainer@@SGHPBDAAV?$CStringT@DV?$StrTraitMFC@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@H@Z) already defined in nafxcwd.lib(afxctrlcontainer2.obj)
1>.\Debug\application-ui.exe : fatal error LNK1169: one or more multiply defined symbols found

How do I solve this issue?

Upvotes: 2

Views: 2551

Answers (1)

s b
s b

Reputation: 131

In your static library go to the STDAFX.H and comment out following preprocessor macro:

#define _AFX_NO_MFC_CONTROLS_IN_DIALOGS

Upvotes: 13

Related Questions