[quoted text, click to view] > The app compiled and run fine in Release mode. When I changed to
> Debug mode, the linker reported the following errors. Is there any
> attribute or directive I can set to avoid the mutliple symbol definitions?
> nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)"
> (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)
I don't know exactly what could cause it, but you can try to track it down.
Add /verbose option to the list of linker options. When linking, a long report
will be produced in the output window. This report will consist of many entries
similar to this:
Found "public: static void __stdcall CObject::operator delete(void *)" (??3CObject@@SGXPAX@Z)
Referenced in nafxcwd.lib(thrdcore.obj)
Referenced in nafxcwd.lib(afxinl1.obj)
Referenced in MyApp.obj
Loaded nafxcwd.lib(afxmem.obj)
It starts with the function name, then lists the object files that reference it,
and finally gives the library and object file where this function was found.
In this report, look up the place where libcmtd.lib(new.obj) was loaded.
Then use the "referenced" entries to find the object files that reference it.
I guess that the object file (and the corresponding source file) that references
code from new.obj and other reported .obj files is the one where you should
start looking for conflicting project settings.
If you are in a hurry, alternative way to debug this project is to disable optimizations
in Release build. It can be done using the following steps:
- In Configuration Manager, create new configuration and copy its settings
from Release configuration
- Disable C++ compiler optimizations (Project properties | Configuration properties |
C/C++ | Optimizations | "Optimization" = "Disabled (/Od)"
- Ensure that debug information is properly generated. The following options
should be present:
Compiler: /Zi
Linker: /debug
(they also can be set in the project settings)
After you have built the new configuration, you should be able to debug it
in the same way as a standard debug build. The only difference will be that
the application is linked with release MFC and CRT libraries, and their
debugging features (like tracing, assertions, etc.) will not be available.
Regards,
Oleg
[VC++ MVP
http://www.debuginfo.com/]