7

I am trying to calculate the primary memory usage for the current process in C language on Windows using:

windows.h psapi.h

PROCESS_MEMORY_COUNTERS_EX pmc;
GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
SIZE_T physMemUsedByMe = pmc.WorkingSetSize;

It gives me the error:

undefined reference to getprocessmemoryinfo@12

Any idea how to fix this? My compiler is mingw32-gcc.exe

Paul R
  • 208,748
  • 37
  • 389
  • 560
user3213918
  • 333
  • 1
  • 6
  • 11

1 Answers1

20

The header file that declares the function is used by the compiler to compile your code. The linker though does need a definition of the external functions that are used. That is typically supplied in an import library. The error message tells you that the linker has no such definition.

Link with

-lpsapi

to provide the linker with the appropriate import library.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • To end the five year long journey to find out how to accept an answer: Just click the check ✓ icon. – Neonit Jul 31 '19 at 09:30