简体   繁体   English

Visual C ++ CRT调试

[英]Visual C++ CRT debugging

I ran into a really nasty linker error when I start using the debugging discussed here . 当我开始使用此处讨论的调试时,遇到了一个非常讨厌的链接器错误。

I managed to narrow it down to the new ( _NORMAL_BLOCK , __FILE__ , __LINE__ ) construct. 我设法将其范围缩小到new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )结构。 As soon as this overload of the new operator was used I get error LNK2005: "void __cdecl operator delete(void *,int,char const *,int)" (??3@YAXPEAXHPEBDH@Z) already defined in ... 一旦使用了新运算符的重载,我就会收到error LNK2005: "void __cdecl operator delete(void *,int,char const *,int)" (??3@YAXPEAXHPEBDH@Z) already defined in ...

If I exclude that object file from the linking process it just points me to another. 如果我从链接过程中排除了该目标文件,它只是将我指向另一个文件。 I haven't verified this but I'm quite sure they all of these object files that clash with MFC use the debug new version of the operator. 我还没有对此进行验证,但是我非常确定它们与MFC冲突的所有这些目标文件都使用了调试器的新版本。

This lead me on a wild goose chase because if you Google this error, all the evidence will tell you that you're mixing CRT and MFC stuff in the wrong order and sure enough, this is what I was doing. 这使我大吃一惊,因为如果您通过Google搜索此错误,则所有证据都将告诉您您以错误的顺序混合了CRT和MFC内容,而且确实可以,这就是我正在做的事情。

I went trough all my object files and libraries with dumpbin /directives and made sure that the order of linking was the right one, despite of all this I never got past that error. 我使用dumpbin /directives所有目标文件和库,并确保链接顺序正确,尽管所有这些我都从未遇到过该错误。

Is the CRT debugging technique inherently incompatible with MFC or is there an explanation for this? CRT调试技术是与MFC本质上不兼容的,还是对此有解释?

I'm not very knowledgeable about MFC and I'm trying to move away from MFC entirely but I'd like to get this to work until that happens. 我对MFC不太了解,我想完全摆脱MFC,但是我希望在这种情况发生之前,让它开始起作用。

MFC applications will detect memory leaks for you when in debug mode. 在调试模式下,MFC应用程序将为您检测内存泄漏。 To get more information about the leak, you can define new to DEBUG_NEW at the top of each file as follows: 要获取有关泄漏的更多信息,可以在每个文件的顶部为DEBUG_NEW定义new,如下所示:

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

For more information, see the MSDN article Memory Leak Detection in MFC 有关更多信息,请参见MSDN文章MFC中的内存泄漏检测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM