Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to getprocessmemoryinfo@12

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

like image 438
user3213918 Avatar asked Jan 26 '14 07:01

user3213918


1 Answers

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.

like image 61
David Heffernan Avatar answered Sep 22 '22 07:09

David Heffernan