XerZetZip
XerZetZip

Reputation: 45

GCC (MinGW) Linker Fails When Trying to Use GetProcessImageFileName

I am trying to retrieve the name of remote processes using "GetProcessImageFileName". However, the GCC (MinGW) linker fails with the following error(s):

<source_file>.c: In function '<function_name>':
 warning: implicit declaration of function 'GetProcessImageFileName' [-Wimplicit-function-declaration]
 GetProcessImageFileName(hProcess, szProcessName, MAX_PATH);
 ^
undefined reference to `GetProcessImageFileName'
collect2.exe: error: ld returned 1 exit status

I've tried compiling with "-lPsapi" and "-lKernel32" but I get the same results. "GetProcessImageFileName" is declared in "Psapi.h".

I'm using a machine with Windows 7 Professional 64-bit and GCC 4.8.1. Any ideas what's going on?

Upvotes: 4

Views: 1005

Answers (1)

user1129665
user1129665

Reputation:

Make sure you define the macro _WIN32_WINNT to be larger or equal 0x0501 (Windows XP, minimum system supports GetProcessImageFileName). Either use the switch -D_WIN32_WINNT=0x0501 or before you include the headers:

#define _WIN32_WINNT 0x0501
#include <Windows.h>
#include <Psapi.h>

Upvotes: 2

Related Questions