Linking for GUI's

Colin Peters colin@bird.fu.is.saga-u.ac.jp
Thu Jul 10 21:15:00 GMT 1997


Not much return mail is going to get to you with this address
                   vvvvvvvvvvvvvvvvvvvvvv
nicole nowell[SMTP:defaultuser@domain.com] wrote:
>Hi all, I have a very simple question that I can't seem to find on the
>archives or the FAQ.  I am trying to learn win32 programming with the
>Nuts and Bolts Book by Schildt.  Whenever I try to build the first
>example it compiles fine, but the linker cannot resolve any of the Win32
>Api functions.  The faq only says the most common functions are linked
>and you may need to link other libraries.  What libraries should I add
>to the gcc line to build GUI apps (I have successfully compiled several
>simple standard C and C++ programs with mains but no WinMain into
>console apps).

Under Cygnus GNU-Win32 you have to use the -mwindows option to compile
GUI applications, and that will include user32 and gdi32 (as well as
kernel32, which is always included). The Minimalist GNU-Win32 has
similar behavior when the -windows flag is used. You can also
manually link in these two libraries like so:

gcc -o foo.exe foo.o bar.o -luser32 -lgdi32 -Wl,--subsystem,windows

This should compile a GUI program and the two extra libraries will
resolve most of the calls made by a standard Windows program. More
unusual functions are grouped into one of the many libxxx.a import
libraries for the Win32 API (I can't remember which directory they're
in, but it's the same one as libkernel32.a, libuser32.a and libgdi32.a).
Although it is unpleasant, you can use nm and grep to search for
functions which you can't locate:

 nm libxxx.a | grep FunctionName

Will display a match for an import library generally only if the given
function is located in the library.

Anyway, that's a start, good luck.

Colin.

-- Colin Peters - Saga Univ. Dept. of Information Science
-- colin@bird.fu.is.saga-u.ac.jp - finger for PGP public key
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list