This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
Problem choosing exe entry point.
- To: cygwin at sources dot redhat dot com
- Subject: Problem choosing exe entry point.
- From: Mo DeJong <mdejong at cygnus dot com>
- Date: Thu, 5 Jul 2001 22:20:43 -0700 (PDT)
Hi all.
I think I have found a problem with the way Cygwin ld
picks the executable entry point when both WinMain() and main()
are available. I would think that passing in the -mwindows flag
(which gets passed to ld as --subsystem windows) would clear
things up and link with WinMain(). Instead, Cygwin ld is
choosing main().
Here is a quick example to demonstrate the problem:
% cat t2.c
#include <windows.h>
#include <winbase.h>
#include <winuser.h>
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
return 1;
}
int main() {
return 0;
}
/* End of t2.c */
Compiled with VC++:
% cl -c t2.c -MD
% link /Out:t2 t2.obj -subsystem:windows msvcrt.lib
% ./t2.exe
% echo $?
1
(The above uses WinMain() as the entry point, as expected)
Compiled with Cygwin gcc.
% gcc -mwin32 -c t2.c
% gcc -mwindows -o t2 t2.o
/usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-2/../../../../i686-pc-cygwin/bin/ld:
warning: cannot find entry symbol _WinMainCRTStartup; defaulting to 00401000
% ./t2.exe
% echo $?
0
(Note how main() was used as the entry point above)
The workaround is to explicitly pass in the WinMain() entry point:
% gcc -mwindows -o t2 t2.o -e _WinMain@16
% ./t2.exe
% echo $?
1
Does this seem like a bug in ld to anyone else?
I would think that passing "--subsystem windows"
should make it default to WinMain() while passing
"--subsystem console" would make it default to
main(). Does that seem reasonable?
Mo DeJong
Red Hat Inc
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/