Re: [Mingw-users] how to compile a win32 executable using kernel32.dll ?
- Date: Wed, 07 Nov 2007 04:17:40 -0800
- From: Brian Dessent <brian@xxxxxxxxxxx>
- Subject: Re: [Mingw-users] how to compile a win32 executable using kernel32.dll ?
James Yu wrote:
> $ make
> gcc -c hello.c
> gcc -o hello hello.o -mwindows -lkernel32
> hello.o:hello.c:(.text+0x79): undefined reference to
> `_GetProcessId'
> collect2: ld returned 1 exit status
> make: *** [all] Error 1
>
> I have no idea what went wrong and appreciate whoever kind enough to
> show me the way to get out of this mess :-)
The problem has nothing to do with linking to kernel32 per se. In fact
"-lkernel32" is implicitly given by the specs file for every link, so it
is totally unnecessary to specify it. You would be hard pressed to
build an executable that *didn't* link to kernel32.dll, in fact, because
it is a critical system component.
No, the problem is that you did not include windows.h which provides the
proper prototype for this function. Compiling with -Wall would have
caught this with a warning about implicit declaration. In fact there is
no such function called "GetProcessId" at all in kernel32, there is only
a GetProcessIdA() and GetProcessIdW(), corresponding to the ANSI and
unicode versions of the API. The header takes care of #defining the
right one for you so that when you use GetProcessId() in your source you
get the desired version.
Brian
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users