Compiling Errors on GetProcessMemoryInfo function
May 16, 2010 at 11:56 am 3 comments
I recently used GetProcessMemoryInfo function to measure memory usage of working processes on Windows. I firstly tried with the example code “Collecting Memory Usage Information For a Process” in MSDN but the compiling produced some external linking errors on my Windows XP box:
Error 1 error LNK2019: unresolved external symbol _GetProcessMemoryInfo@12 referenced in function “void __cdecl PrintMemoryInfo(unsigned long)” (?PrintMemoryInfo@@YAXK@Z)
Error 2 error LNK2019: unresolved external symbol _EnumProcesses@12 referenced in function _main
Error 3 fatal error LNK1120: 2 unresolved externals
To fix this issue, I added “pragma comment” instruction to places a library-search record in the object file and compiling is now working fine.
#include <windows.h>
#include <stdio.h>
#include <psapi.h>
#pragma comment(lib, “psapi.lib”) //added
Entry filed under: C++ Programming, Windows. Tags: 'error_log' was not declared in this scope, c# getprocessmemoryinfo, Compiling Errors on GetProcessMemoryInfo function, error 1 error lnk2019: unresolved external symbol _getprocessmemoryinfo@12 referenced in function _, error lnk2019: unresolved external symbol _ getprocessmemoryinfo@12 referenced in function "void __cdecl printmemoryinfo(unsigned long, error lnk2019: unresolved external symbol _getprocessmemoryinfo, error lnk2019: unresolved external symbol _getprocessmemoryinfo@12 referenced in function, error lnk2019: unresolved external symbol _getprocessmemoryinfo@12 referenced in function "void __cdecl, externes symbol "_getprocessmemoryinfo@12" in funktion "_main", getprocessmemoryinfo error lnk2019, getprocessmemoryinfo example, getprocessmemoryinfo lnk2019, getprocessmemoryinfo unresolved external, getprocessmemoryinfo@12 referenced in function, lnk2019 getprocessmemoryinfo, lnk2019: unresolved external symbol getprocessmemoryinfo referenced in function, unresolved external symbol _getprocessmemoryinfo, unresolved external symbol _getprocessmemoryinfo@12, unresolved external symbol _getprocessmemoryinfo@12 referenced in function "void __cdecl printmemoryinfo.
Export data from MySQL into a text file Example Code of Multithreading in C# GUI Application
3 Comments Add your own
Leave a Reply Cancel reply
Trackback this post | Subscribe to the comments via RSS Feed
1.
Prasad Chothwe | February 23, 2012 at 5:46 am
if Above Pragma don’t work then use
#pragma comment(linker, “/DEFAULTLIB:psapi.lib”)
2.
oddant | February 25, 2012 at 2:39 pm
thanks, it works like a charm now, you save me from getting some headaches trying to find out how to resolve that.
3.
Alex Adams | May 19, 2015 at 7:39 am
That solved my problem – it would have taken about a week otherwise 😉 thanks very much.