This is the mail archive of the 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]

Re: Linking with .LIB files

David W Palmer wrote:
> Text item:
>      For those who are watching: Colin Peter's text is left justified, mine is
>      indented.
> David W Palmer[] wrote:
> >     So, I have a simple program which uses OpenGL and I link with the
> >     following:
> >
> >     link simple.o libuser32.a glu32.lib opengl32.lib libgdi32.a
> >     /subsystem:windows /machine:i386

> >      LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
> >      simple.exe : fatal error LNK1120: 1 unresolved externals
> >      make: *** [simple.exe] Error 25
> >
> >     No .EXE is generated.  And the answer is... what?

Just what sort of thing is simple.o?  If it is a POSIXish
thing that has a main() and uses the POSIXish stuff provided by
cygwin.dll then you need crt0.o and libcygwin.a and possibly others, and
tell the linker that the entry point is _mainCRTStartup.  If it's a
win32ish thing then you should be providing your own _WinMainCRTStartup
or tell the linker just what *is* your entry point.

> This suggests to me that you need to include crt0.o in your link line
> explicitly, since that's where _WinMainCRTStartup should be resolved.
> Well, actually in the Cygnus sources it's not, but you could just add
> a _WinMainCRTStartup entry point which calls the _mainCRTStartup
> entry point and it should work OK I think.
>      Yes, I thought of that too.
>      //f/pgming/OpenGL/simple$ make
>      link simple.o crt0.o libuser32.a glu32.lib opengl32.lib libgdi32.a

You still haven't told the linker what the entry point is or
provided a _WinMainCRTStartup; read Colin's comments above again.

>      /subsystem:windows /machine:i386
>      Microsoft (R) 32-Bit Incremental Linker Version 5.00.7022
>      Copyright (C) Microsoft Corp 1992-1997. All rights reserved.
>      crt0.o : error LNK2001: unresolved external symbol _cygwin_crt0
>      LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
>      simple.exe : fatal error LNK1120: 2 unresolved externals
>      make: *** [simple.exe] Error 25
>      //f/pgming/OpenGL/simple$
>      So, I can trade WinMainCRTStartup() for cygwin_crt0().

No, now you are missing both.

>      Not much
>      progress.  Though, this has to be defined somewhere!  Which library?

libcygwin.a.  cygwin_crt0 calls dll_crt0 in cygwin.dll.

>      Unfortunately, I don't know how to list the functions in a library.

nm for *.a

>      BTW: instead of defining WinMainCRTStartup(), it's easier to use the
>      link option /ENTRY:mainCRTStartup.

But you didn't.  You need to tell the linker your entry point or provide
a _WinMainCRTStartup.

<J Q B>
For help on using this list, send a message to
"" with one line of text: "help".

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