Reputation: 353
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
Upvotes: 7
Views: 6237
Reputation: 612954
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.
Upvotes: 21