From: ErnieC AT ix DOT netcom DOT com (Ernest Clayton Cordell, Jr.) Subject: RE: Linking problems 18 Sep 1997 07:00:26 -0700 Message-ID: <01BCC416.FEAB6020.cygnus.gnu-win32@rvl-md2-06.ix.netcom.com> To: "'Colin Peters'" Cc: "'gnu-win32 AT cygnus DOT com'" Colin, No, I didn't ask the question, but it is a very good answer and I thank you. I was beginning to figure out as much, but it was a long and painful process in which I think I must have read a couple of websites. I think it is in a FAQ, or readme or some such thing somewhere, but not in the present format -- I gleaned much of what you put here from several pages, but I don't think a lot of it had sunk in (cognitively) yet. There are still quite a few things I need to figure out, but I'm not ready to ask the questions yet; I am trying to "assemble my basic toolkit" and wait until I hit an obstacle before I trouble anyone with the questions. This is not a comment on approach, this "study style" works best for me personally. Thanks to all, Ernie ---------- From: Colin Peters Sent: Wednesday, September 17, 1997 11:58 PM To: 'Fredrik Eldh' Cc: 'GNU-Win32' Subject: RE: Linking problems Fredrik Eldh[SMTP:lazermasken AT hotmail DOT com] wrote: >I'm a newbie when it comes to Gnu-Win32 and I'm having trouble when I >try to link any Win32 program. The linker says I have 'undefined >references' to all the Win32 API functions. I use the following command >line to compile and link: "gcc program.c". > >Now, please don't tell me to go look this up in an FAQ or something, >I've already done that and it didn't make me wiser. It's pretty simple actually, and it should be a FAQ. GNU-Win32 requires that you explicitly link the import libraries for whatever Win32 API functions that you are going to use, with the exception of kernel32, which is linked automatically (because the startup and/or built-in code uses it). For example, to use graphics functions (GDI) you must link with gdi32 like this: gcc -o foo.exe foo.o bar.o -lgdi32 or (compiling and linking in one step): gcc -o foo.exe foo.c bar.c -lgdi32 The regular Cygnus setup allows you to use the option -mwindows on the command line to include a set of the basic libraries (and also make your program a GUI program instead of a console program), including user32, gdi32 and, IIRC, comdlg32. A few notes: - Do not ever include -lkernel32 on your link line (unless you are invoking ld directly, in which case I share your pain). - Do not include the same import library twice on your link line. - Put import libraries last on your link line, or at least after all the object files and static libraries that reference them. The first two are related to problems the linker has currently when import libraries are referenced twice. Tables get messed up and programs crash randomly. The last point has to do with the fact that GCC processes the files listed on the command line in sequence and will only resolve references to libraries if they are given after the file that makes the reference. Anyway, hope that helped. Colin. PS. Actually GCC is not being any different from MSVC or other Win32 compilers about this. Just open up the build options dialog and look for the list of libraries to link. By default you'll find a whole mess of import libraries including all the ones I mentioned above (at least the last time I looked). -- Colin Peters - Saga Univ. Dept. of Information Science -- colin AT bird DOT fu DOT is DOT saga-u DOT ac DOT 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 AT cygnus DOT com" with one line of text: "help". - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".