【问题标题】:VsCode crtdbg.h not found, how to fix?找不到VsCode crtdbg.h,如何解决?
【发布时间】:2019-03-05 22:57:45
【问题描述】:

试图检查内存泄漏工具,但 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 一起使用吗?

【问题讨论】:

  • 这个答案不起作用
  • source.c:24:5: error: '_CrtDumpMemoryLeaks' was not declared in this scope _CrtDumpMemoryLeaks(); 这就是使用帖子答案时出现的内容
  • 我有其他方法可以检查它是否适合你吗?
  • 我只是投了赞成票,我希望有人能知道如何处理它,我在谷歌上搜索它但还没有解决方案

标签: c visual-studio-code crtdbg.h


【解决方案1】:

我认为 VSCODE 无法访问头文件 crtdbg.h ,请使用以下简单方法进行测试。也许它解决了你的问题:

1- 以管理员身份运行 VS2019 的开发人员命令提示符。我强调以管理员身份运行,不要运行。

2- 类型代码。

3- 打开项目文件夹。

4- 快乐编码并享受它。

【讨论】:

    【解决方案2】:

    This 应该有帮助...

    #ifdef _MSC_VER
    #include <crtdbg.h>
    #else
    #define _ASSERT(expr) ((void)0)
    
    #define _ASSERTE(expr) ((void)0)
    #endif
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-26
      • 2021-05-14
      • 2019-10-19
      • 1970-01-01
      • 2014-09-24
      • 2012-03-02
      • 2021-04-09
      • 2016-03-13
      相关资源
      最近更新 更多