Win32: With the latest gcc (2.95, pre-release), we can have binary
[platform/upstream/glib.git] / README.win32
1 General
2 =======
3
4 For more information about the port or GLib, GTk+ and the GIMP to
5 native Windows, and pre-built binary packages, see
6 http://www.iki.fi/tml/gimp/win32/ . "Native" means that we use the
7 Win32 API only, and not any POSIX emulation layer except that provided
8 by the Microsoft runtime C library. Additionally, a pthreads emulation
9 library is used.
10
11 To build GLib on Win32, you can use either the Microsoft compiler and
12 tools, or gcc. Both the compiler from MSVC 5.0 and from MSVC 6.0 have
13 been used successfully. With gcc I mean the gcc-2.95 pre-release as
14 distributed by Mumit Khan, running under cygwin-b20.1. To successfully
15 use gcc, follow the instructions below. We want to use gcc
16 -mno-cygwin, i.e. produce executables (.exe and .dll files) that do
17 *not* require the cygwin runtime library. This is sometimes called
18 "mingw32".
19
20 To test the GLib functions, go to the tests subdirectory and enter
21 `nmake -f makefile.msc check` or `make -f makefile.cygwin check`.
22
23 If you would want to use the cygwin tools to generate executables that
24 *do* use the cygwin runtime, the normal Unix configuration method
25 should work as if on Unix. But it won't produce DLLs. At least I
26 haven't succeeded in that.
27
28 With a little work, it might be possible to use the ./configure
29 mechanism also with a "mingw32" configuration.
30
31 The following preprocessor macros are defined in glibconfig.h and used
32 for conditional compilation related to Win32:
33
34 - WIN32 is defined when compiling for the Win32 platform, regardless
35   if using the X11 or Win32 windowing API (in the case of GLib, this
36   dimension isn't significant), regardless whether using a more or
37   less complete POSIX emulation runtime layer (like Cygwin) or not.
38
39 - NATIVE_WIN32 is defined when compiling for Win32, *and* without
40   any POSIX emulation, other that to the extent provided by the
41   bundled Microsoft C library (msvcrt.dll) and the pthreads-win32
42   library. For instance, pathnames are in the native Windows syntax.
43
44 The Win32 port uses the combination with both of those on. As these
45 are in glibconfig.h, they are available to all source files that use
46 GLib (or GTk+, which uses GLib).
47
48 Additionally, there are the compiler-specific macros:
49 - _MSC_VER is defined when using the Microsoft compiler
50 - __GNUC__ is defined when using GCC
51
52 Some of the usage of these macros used to be a bit mixed up, and had
53 to be straightened out when adding the gcc support. In particular, I
54 used to check for _MSC_VER in some places where I really wanted to
55 check for the Microsoft C library, and those checks has now been
56 changed to NATIVE_WIN32. NATIVE_WIN32 ought to be renamed to
57 USE_MSVCRT.
58
59 Pthreads library
60 ================
61
62 Before building you must get the pthreads library for Win32 from
63 http://sourceware.cygnus.com/pthreads-win32/. The pthreads-win32
64 snapshot from 1999-05-30 is the one that should be used. Edit the
65 location of the pthreads library and include files in makefile.msc or
66 makefile.cygwin. The pthreads distribution includes the precompiled dll
67 and import libraries both for MSVC and gcc.
68
69 The pthreads for Win32 package that the thread support uses supposedly
70 isn't quite ready yet, and thus threads stuff should not be relied
71 upon for anything serious.
72
73 Where are the makefiles?
74 ========================
75
76 If you are building from a CVS snapshot, you will not have any
77 makefile.msc or makefile.cygwin file. You should copy the
78 corresponding makefile.msc.in or makefile.cygwin.in file to that name,
79 and edit the line that sets GLIB_VER to the correct version number.
80
81 This is done automatically when an official distribution package is
82 built.
83
84 Building with MSVC
85 ==================
86
87 If using the Microsoft toolchain, build with `nmake -f
88 makefile.msc`. Install with `nmake -f makefile.msc install`. 
89
90 Building with gcc
91 =================
92
93 The gcc support was added quite recently, but seems to work. Debugging
94 with gdb works. I use the latest and greatest gcc and mingw32.
95 Somewhat earlier versions will also work, but you are on your own.
96
97 Fetch the gcc-2.95 developer snapshot from
98 ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/snapshots/gcc-2.95-19990715/.
99 Install it somewhere, for instance \gcc-2.95.
100
101 Fetch the mingw runtime snapshot from 1999-07-15 from
102 ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/runtime/. You
103 must fix two bugs in it:
104
105 1) Fix the prototype and call to __getmainargs() in init.c to include
106 one more parameter, an int *, which should be passed the address of a
107 zero int. Code snippets below:
108
109 ...
110 #ifdef __MSVCRT__
111 extern void __getmainargs(int *, char***, char***, int, int *);
112 #else
113 ...
114 #ifdef __MSVCRT__
115         int newmode = 0;
116         (void) __getmainargs(&_argc, &_argv, &dummy_environ, _CRT_glob, &newmode);
117 #else
118 ...
119
120 2) Fix the type of the function __p___argv() in stdlib.h to be char***,
121 not char**.
122
123 Build the mingw32 runtime and install the libraries in the
124 gcc-2.95\H-i586-cygwin32\lib directory, and the headers in the
125 gcc-2.95\H-i586-cygwin32\i586-cygwin32\include\mingw32 directory.
126 Remember to build and install also the w32api import libraries and
127 headers.
128
129 I prefer to use the msvcrt runtime and not the default
130 crtdll. Especially, as the pthread library also uses msvcrt, using
131 crtdll would probably not be a good idea at all. Using msvcrt can be
132 achieved by applying a few changes to the specs file.
133
134 The specs file is in gcc-2.95\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\2.95
135
136 The necessary changes are: replace -lcrtdll with -lmsvcrt, replace
137 crt1 with crt2, change -lmoldname to -lmoldname-msvc, and define
138 __MSVCRT__.
139
140 Next, go back to the GLib directory and build using `make -f
141 makefile.cygwin`.  Building the dlls uses the script build-dll which
142 is somewhat of a hack. But I couldn't get things working in a cleaner
143 way.
144
145 --Tor Lillqvist <tml@iki.fi>