Compiling with MinGW for Win32

only for RuBoard - do not distribute or recompile

Compiling with MinGW for Win32

This section covers the MinGW gcc compiler for the Win32 platform. This is a port of the GNU gcc compiler, and with a bit of effort, it can be used to compile and run GTK+ and MySQL client applications. You will have to download and install several * .zip or * .tar.gz files. The gcc command line has to be structured correctly, but it is possible.

What Is MinGW?

For our purposes, MinGW is gcc for Windows . That is all that will be used of it in this context, but in truth, that is selling it short. In a larger context, it is a full set of GNU tools that have been ported to the Win32 environment.

MinGW is the Minimalist GNU for Windows port of the gcc compiler. Its biggest selling point is that it allows the developer to compile programs on Windows that don t rely on any third-party dll files. (Cygwin is a prime example.) In addition to the gcc compiler, the MinGW project also provides a Windows port of GNU make and GNU Debugger (gdb), all under the GNU General License. At the time this book was written, the MinGW Web site directed browsers to http://www.gnu.org/ copyleft /gpl.html for further explanation of the GPL.

The MinGW Web site is http://www.mingw.org/.

Files and URLs Needed

In addition to the Glade, GTK+, Glib, and MySQL client files needed for the section on building for Windows with MS Visual C++ in Chapter 10, what follows is a list of files needed to build a MySQL/GTK+ application with the gcc compiler from MinGW.

You will need the MinGW distribution from http://www.mingw.org/. Specifically, you may need some or all of the following files (or their newest equivalents):

  • binutils-2.10.91-20010114.zip

  • binutils-19990818-1- msvcrt .zip

  • gcc-2.95.2-1-msvcrt.zip

  • ld-2.10.91-20010126.zip

  • mingw-msvcrt-19991107.zip

  • mingw-runtime-0.5-20010221.tar.gz

  • w32api-0.5-20010301.tar.gz

Some files that are needed are included in multiple files, and some may not be needed unless you want to access the C Windows API.At the very minimum, you will need the gcc-version-msvcrt , mingw-msvcrt-datetime , and binutils-datetime-msvcrt files.

You will, of course, need the GTK+, GDK, Glib, and other files from Tor Lilquist s Web site at http:// user .sgic.fi/~tml/gimp/win32/. Refer to Chapter 10 for specifics.

You will also need some of the MySQL client for windows files. The URL for those is http://www.mysql.com/. You can refer to Chapter 10 for specifics.

You will also need a very special set of files from Jan Dvorak s JohnyDog s MinGW ports Web site at http://doga.go.cz/ports.html. (You can also download this file from this book s companion Web site.) Specifically, you will need 3.23.32- mingw32-binary.tar.gz (or its most recent equivalent). These are the MySQL client files modified for MinGW, but the most important is the libmysqlclient.a file, which gcc will need in order to properly compile the application.

There will also be copies of most of the above ”to the extent possible ”at the book s companion Web site on http//www.newriders.com.

Setup and Compile Instructions

For purposes of this demonstration, I have chosen the bar_line executable to compile and run as a demonstration rather than all the executables in the KBI application. In other words, change all instances that call to the bar/line code or executable to scatter (or whatever your target is) in the call to gcc.exe at the end of Listing 13.5, and you should be able to compile and link. If you understand the mechanics of the gcc command line in Listing 13.5, you should be able to use this to produce any Windows executable.

Listing 13.5 is the batch file that was put together to compile the bar_line.exe file. It uses the same source code as its Linux version with the following exceptions:

  • The addition of #include <windows.h> to the top of barline_utils.c

  • A recursive call to limits.h from limits.h was commented out at the end of the limits.h file

Also, I had to do the following in order to get a clean compile and link:

  • Put libbfd-2.10.91 in the same directory location as a s.exe ; from MinGW.

  • Put crt2.o in the same subdirectory as the source code; also from MinGW.

  • Put lib mingw32.a , libmoldname.a , libuser32.a , libkernel32.a , libadvapi32.a , and libshell32.a in the same subdirectory as the MinGw specs file (the name of the file is specs , nothing more).

Listing 13.5 Windows Batch File for Compiling bar_line.exe , the Windows Version of the Bar/Line Chart from the KBI Application
 @echo off  rem . This is the gcc command line compile for the Win32 platform.  rem . Having WinZip will make all this MUCH easier because  rem . most of the target files listed here are downloaded as  rem . *.zip files.  rem . www.winzip.com.  rem .  rem . Get the newest file when you run this batch file, not  rem . necessarily the files listed here; they are just the ones  rem . current at the time the book was written.  rem . ===========================================================  rem . URLs and files needed at various places.  rem . ===========================================================    rem . gcc for Windows  rem . URL:      http://www.mingw.org./  rem . File:     mingw-runtime-0.5-200102  rem .  rem . MySQL for MinGW files, including libmysqlclient.a  rem . URL:     http://doga.go.cz/ports.html  rem . File:    MySQL-3.23.32-mingw32-binary.tar.gz  rem .  rem . GTK+, GDK, GLib, etc, for Windows  rem . URL:     http://user.sgic.fi/~tml/gimp/win32/  rem . Files:   glib-dev-20001226.zip, glib-src-2001226.zip,  rem .          gtk+-dev-20001226.zip, gtk+-src-20001226.zip  rem .  rem . zlib library, needed by the MySQL for MinGW files  rem . URL:     http://penguin.at0.net/~fredo/files/  rem . File:    zlib-1.1.3-mingw.zip  rem . ===========================================================  rem . Set the system path to search for the executables. The  rem . examples below are for the book's development system; you  rem . will need to change the paths.  rem . ===========================================================  rem . Path Variable:  d:\mingw\bin  rem . Location of:    gcc.exe  rem . File (mingw):   gcc-2.95.2-1.msvcrt.zip  rem . Path Variable:  d:\mingw\binutils\bin  rem . Location of:    as.exe, ld.exe  rem . Files (mingw):  binuitls-2.10.91-20010114.zip,  rem .                 ld-2.10.91-20010126.zip  PATH=d:\mingw\bin\;d:\mingw\binutils\bin\;  rem . Set the current directory to the location of this batch file.  D:  cd \NewRiders\book\ch12\r3\src\  rem . ===========================================================  echo Starting compile...  rem . ===========================================================  rem . The order of the *.c files is important.  rem .  rem . -Wall               show all warnings  rem . -o bar_line.exe     the executable name  rem . *.c                 the source files  rem . -I                  "Include" directories for *.h files  rem . -l                  link the following library; the file  rem .                       gcc will search for is actually called  rem .                       libwhatever.a, but on the command line  rem .                       the link command is -lwhatever  rem . -L                  Look in these directories for the  rem .                       library files indicated by the -l flags  rem . Option:  -ID:\mingw\bin\mingwbinary\include\mysql\  rem . What:    mysql header files for mingw  rem . Option:  -ID:\MySQL\Win32\include\  rem . What:    mysql header files from mysql, any not covered previously  rem . Option:  -ID:\gtk\src\gtk+\  rem .          -ID:\GLIB\src\glib\  rem .          -ID:\GTK\src\gtk+\gdk\  rem .          -ID:\gtk\src\gtk+\gtk\  rem . What:    gtk\gtk.h, glib.h and other header files and  rem .          any other gtk+ and gdk files not already covered.  rem . Options:  -ID:\MySQL\Win32\lib\opt\  rem .           -ID:\mingw\lib\gcc-lib\i386-mingw32msvc.95.2\include\  rem .           -ID:\mingw\msvcrt\i386-mingw32msvc\include\  rem . What:     assorted *.h files  rem . Option:   -ID:\mingw\msvcrt\i386-mingw32msvc\lib\  rem .           assorted *.a files  rem . Option:   -mno-cygwin  rem . Purpose:  don't compile with the cygwin dll if it is present  rem . Option:   -fnative-struct  rem . Purpose:  the "struct" layout is the same as that used by MS VC++  rem . Option:  -lgdk-1.3  rem .          -lgtk-1.3  rem .          -lgmodule-1.3  rem .          -lglib-1.3  rem . What:    gtk and gdk libraries  rem . Option:   -lmysqlclient  rem . What:     link in file libmysqlclient.a  rem . Option:   -lwsock32  rem . Purpose:  needed with the libmysqlclient.a file used  rem . Option:   -lzlib  rem . What:     link file libzlib.a  rem . Purpose:  compression and decompression  rem . Option:   -LD:\mingw\bin\mingwbinary\lib  rem . What:     location of file libmysqlclient.a; this one has    rem .              been put first so that any files found in this  rem .              directory get used, even if duplicates or different  rem .              versions are found in any of the directories below.  rem . Option:   -LD:\mingw\msvcrt\i386-mingw32msvc\lib\  rem .           -LD:\MySQL\win32\lib\opt  rem .           Other directories to search in case libmysqlclient.a  rem .              is not found in the previous directory.  rem . Option:  -Ld:\GLIB\src\glib  rem .          -Ld:\GTK\src\gtk+\gtk  rem .          -Ld:\GTK\src\gtk+\gdk  rem .          -LD:\GLib\src\glib\gmodule  rem . What:    libgtk-1.3.a, libgdk-1.3a, etc. Same as Chapter 10.  rem . Option:  -LD:\mingw\lib\zlib  rem . What:    location of libzlib.a  rem . ==============================================================  rem . Here is the actual call to gcc  rem  ===============================================================  gcc -Wall -o bar_line.exe main.c support.c interface.c callbacks.c barline_utils.c  ID:\mingw\bin\mingwbinary\include\mysql\ -ID:\MySQL\Win32\include\ - ID:\gtk\src\gtk+\ -ID:\GLIB\src\glib\ -ID:\GTK\src\gtk+\gdk\ - ID:\gtk\src\gtk+\gtk -ID:\MySQL\Win32\lib\opt\  -ID:\mingw\lib\gcc-lib\i386-mingw32msvc.95.2\include\ -ID:\mingw\msvcrt\i386- mingw32msvc\include\ -ID:\mingw\msvcrt\i386-mingw32msvc\lib\ -mno-cygwin - fnative-struct -lgdk-1.3 -lgtk-1.3 -lgmodule-1.3 -lglib-1.3 -lmysqlclient  -lwsock32 -lzlib -LD:\mingw\bin\mingwbinary\lib -LD:\mingw\msvcrt\i386- mingw32msvc\lib\ -Ld:\GLIB\src\glib -Ld:\GTK\src\gtk+\gtk -Ld:\GTK\src\gtk+\gdk  -LD:\MySQL\win32\lib\opt -LD:\GLib\src\glib\gmodule -LD:\mingw\lib\zlib  echo Done.  rem . You may need to include the math library, -lm.  rem . The Win32 version of -lz is the -lzlib above.  rem . Good Luck! 

Figure 13.2 shows the compiled executable running on a Windows 95 machine. Remember (from Chapter 10) that the server name as called from within the MySQL client code is einstein and that einstein is a Samba share on this network, which allows the Windows machines to resolve the server name.

Figure 13.2. bar_line.exe running on Windows95. Notice the stock icon in the upper-left corner of the application window; contrast that with Figure 10.11.
graphics/13fig01.gif
only for RuBoard - do not distribute or recompile


MySQL Building User Interfaces
MySQL: Building User Interfaces (Landmark)
ISBN: 073571049X
EAN: 2147483647
Year: 2001
Pages: 119

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net