title: G++ link against psapi in Cygwin
body: <p>I have a C++ project which I used to build with Visual C++. In the project I used:  </p>
  
  <pre><code>#pragma comment(lib, "psapi")
  </code></pre>
  
  <p>in order to link against <code>psapi</code>.</p>
  
  <p>G++ does not seem to support this syntax, though. From what I understand you would have to pass a <code>-l</code> flag with the name of the library in order to link against it. </p>
  
  <p>I tried <code>-lpsapi.lib</code> and <code>-lpsapi</code>.<br>
  But gcc wasn't able to find it.<br>
  So I searched where I could find it and apparently it is in <code>/lib/w32api/libpsapi.a</code>. So I tried <code>-llibpsapi.a</code> and <code>-llibpsapi</code>, but it is still not able to find it.<br>
  So I tried to add the path using the <code>-L</code> flag like so <code>-L/lib/w32api</code>, but it would still not find it.<br>
  Then I tried adding two environment variables instead of the <code>-L</code> flag:  </p>
  
  <pre><code>export LIBRARY_PATH=/lib/w32api
  export LD_LIBRARY_PATH=/lib/w32api
  </code></pre>
  
  <p>But it is still not working. </p>
  
  <p>The error message is:</p>
  
  <pre><code>/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -llibpsapi
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>And my last attempt was:</p>
  
  <pre><code>g++ -llibpsapi -o Example.exe Stuff.cpp Example.cpp -static
  </code></pre>
  
  <p>If I leave the <code>-l</code> flag out entirely, then I get these errors btw:</p>
  
  <pre><code>/tmp/cctDMx8f.o:Stuff.cpp:(.text+0x139): undefined reference to `EnumProcessModules'
  /tmp/cctDMx8f.o:Stuff.cpp:(.text+0x139): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `EnumProcessModules'
  /tmp/cctDMx8f.o:Stuff.cpp:(.text+0x181): undefined reference to `EnumProcessModules'
  /tmp/cctDMx8f.o:Stuff.cpp:(.text+0x181): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `EnumProcessModules'
  /tmp/cctDMx8f.o:Stuff.cpp:(.text+0x1db): undefined reference to `GetModuleBaseNameA'
  /tmp/cctDMx8f.o:Stuff.cpp:(.text+0x1db): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `GetModuleBaseNameA'
  collect2: error: ld returned 1 exit status
  </code></pre>