试图检查内存泄漏工具,但是Vscode不识别#include <crtdbg.h>。
以下是代码:
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#include <stdio.h>
#include <string.h>
int main()
{
char *word = "this still relevant.";
char *mem = (char *)malloc(sizeof(word));
strcpy(mem, word);
printf("%s", mem);
system("pause");
_CrtDumpMemoryLeaks();
}编译错误:
source.c:4:10: fatal error: crtdbg.h: No such file or directory
#include <crtdbg.h>如何正确地包含crtdbg.h?
PS:我使用的是MinGW编译器,除了它什么都能工作。
编辑1:另一个帖子的解决方案不起作用。如果我使用建议的代码,就会出现这种情况。
source.c:24:5: error: '_CrtDumpMemoryLeaks' was not declared in this scope
_CrtDumpMemoryLeaks();编辑2:有人使用VsCode和MinGW吗?
发布于 2020-11-17 14:43:15
我认为VSCODE无法访问头文件、crtdbg.h、Pease,这是一种简单的方法。也许它解决了你的问题:
1-作为管理员开发人员命令提示运行VS2019。我强调以管理员身份运行,而不是运行。
2-类型代码。
3-打开项目文件夹。
4-快乐的编码和享受它。
https://stackoverflow.com/questions/55012944
复制相似问题