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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With