3

Trying to check memory leak tool but Vscode doesn't recognize #include <crtdbg.h>.

Here is the code:

#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();
}

The compile error:

source.c:4:10: fatal error: crtdbg.h: No such file or directory
#include <crtdbg.h>

How do I properly include crtdbg.h?

PS: I'm using MinGW compiler, everything works except that.

EDIT 1: The solution of that other post doesn't work. If I use the suggested code this appear.

source.c:24:5: error: '_CrtDumpMemoryLeaks' was not declared in this scope
     _CrtDumpMemoryLeaks();

EDIT 2: Does anyone uses VsCode with MinGW?

Govind Parmar
  • 20,656
  • 7
  • 53
  • 85
Jackpot
  • 47
  • 1
  • 5

1 Answers1

1

I think that VSCODE couldn't access to header file, crtdbg.h , Pease test a simple following way. Maybe it solved your problem:

1- Run as administrator Developer Command prompt for VS2019. I emphasized run as administrator no run.

2- Type Code .

3- Open project folder.

4- Happy coding and enjoy it.

mm.persian
  • 21
  • 3