PRB: L2025 with a CWinApp-Derived Class in an Extension DLL |
Q117564
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), included with:
- Microsoft C/C++ for MS-DOS, version 7.0
- Microsoft Visual C++, versions 1.0, 1.5
SYMPTOMS
It can be useful to define and export (not necessarily instantiate) a CWinApp-derived class within an MFC-extension DLL (_AFXDLL defined). However, the linker generates the following:
d:\msvc\mfc\lib\mfc250d.lib(dumpout.cpp) : error L2025: _AfxTrace : symbol defined more than once d:\msvc\mfc\lib\mfc250d.lib(afxmem.cpp) : error L2025: void __far* __far __cdecl operator new(unsigned int) : symbol defined more than once d:\msvc\mfc\lib\mfc250d.lib(afxmem.cpp) : error L2025: void __far* __far __cdecl operator new(unsigned int,char const __far*,int) : symbol defined more than once d:\msvc\mfc\lib\mfc250d.lib(afxmem.cpp) : error L2025: void __far __cdecl operator delete(void __far*) : symbol defined more than once d:\msvc\mfc\lib\mfc250d.lib(afxmem.cpp) : error L2025: public: static void __far* __far __cdecl CObject::operator new(unsigned int) : symbol defined more than once d:\msvc\mfc\lib\mfc250d.lib(afxmem.cpp) : error L2025: public: static void __far* __far __cdecl CObject::operator new(unsigned int,char const __far*,int) : symbol defined more than once d:\msvc\mfc\lib\mfc250d.lib(afxmem.cpp) : error L2025: public: static void __far __cdecl CObject::operator delete(void __far*) : symbol defined more than once d:\msvc\lib\ldllcew.lib(fmalloc.asm) : error L2025: __fmalloc : symbol defined more than once d:\msvc\lib\ldllcew.lib(fmalloc.asm) : error L2025: __ffree : symbol defined more than once
CAUSE
The CWinApp::_ForceLinkage member function of the CWinApp class forces the routines mentioned in the error messages to be linked in from the file DLLINIT.CPP. This member function is used only by the MFC libraries. Having these routines defined in DLLINIT.CPP as well as in the class libraries causes the error message "symbol defined more than once".
The _fmalloc, _free, new, and delete errors can also be caused by a call to AfxCheckMemory() in a MFC extention DLL. This problem can occur with or without a CWinApp derived class.
RESOLUTION
To work around the problem, override CWinApp::_ForceLinkage(). The function should do nothing, but it prevents the base class function from linking in the DLLINIT.CPP file.
This is not a problem with Visual C++ 32-bit Edition, because there is no CWinApp::_ForceLinkage. Calling AfxCheckMemory() is also safe from a 32-bit extension DLL.
MORE INFORMATION
The following sample code is an example of a CWinApp-derived class that might be included in an _AFXDLL DLL with a _ForceLinkage() member declaration:
Sample Code
/* Compile options needed: /D_AFXDLL */ class CMyApp: public CWinApp { ... void _ForceLinkage() { #ifndef _WINDLL CWinApp::_ForceLinkage(); #endif } ... };
Additional query words: 7.00 1.00 1.50 2.00 2.50
Keywords : kb16bitonly kbDLL kbMFC kbVC kbprb
Issue type : kbprb
Technology : kbAudDeveloper kbMFC
Last Reviewed: May 8, 2001 |