title: Why does the compiler throw "undefined reference to ..." despite providing all needed libraries in the arguments
body: <p>I'm working on a program that will monitor the usage of chosen programs and will log it into a .csv file. That way, I can determine what programs use up the most of a certain resource while I run a game in full-screen. I have included the psapi header like so:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>...
  #include &lt;psapi.h&gt;
  ...
  </code></pre>
  
  <p>And I compile with MinGW's G++ with the following options and necessary libraries for the function I'm using (libraries were from the documentation of the function): <code>g++ -lkernel32 -lpsapi test.cpp -o test.exe</code></p>
  
  <p>Yet it still throws the error:</p>
  
  <pre><code>c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\james\AppData\Local\Temp\cclpYDm2.o:test.cpp:(.text+0x3e7): undefined reference to `GetProcessMemoryInfo@12'
  collect2.exe: error: ld returned 1 exit status
  </code></pre>
  
  <p>I feel that either something is wrong with my library or there's something I'm doing wrong. I've tried surrounding the header with "extern "C"" and I still get the same exact message. I have also verified that the library exists; if it did not, the compiler would have thrown a different error. <code>#pragma comment</code> does not work either, and using the <code>-static</code> flag has no effect. I have also tried defining the PSAPI_VERSION macro and setting it to 1, placing it before the include statement of psapi.</p>
  
  <p>TL;DR: Compiler is throwing an undefined reference error despite having correct libraries. I suspect it's either:</p>
  
  <ul>
  <li>Library was installed incorrectly</li>
  <li>I'm doing something wrong on linking</li>
  </ul>