This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Problem choosing exe entry point.


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]