Cygwin support contributed by Stefan Ondrejicka <ondrej@idata.sk>.
[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 binaries (DLLs), surf to
6 http://www.gimp.org/win32/ . "Native" means that we use the Win32 API
7 only, and no POSIX (Unix) emulation layer except that provided by the
8 Microsoft runtime C library, and a pthreads emulation library.
9
10 To build GLib on Win32, you can use either gcc or the Microsoft
11 compiler and tools. Both the compiler from MSVC 5.0 and from MSVC 6.0
12 have been used successfully.
13
14 But note that to just *use* GLib on Windows, there is no need to build
15 it, prebuilt DLLs are available from the webiste above.
16
17 With gcc I mean gcc-2.95.2 as distributed by Mumit Khan, either as a
18 mingw version (preferred), or running under cygwin. To successfully
19 use gcc, follow the instructions below. We want to use gcc
20 -mno-cygwin, i.e. produce executables (.exe and .dll files) that do
21 *not* require the cygwin runtime library. This is called "mingw".  I
22 also use the -fnative-struct flag, which means that in order to use
23 the prebuilt DLLs (especially of GTK+), you *must* also use that flag.
24 (This flag means that the struct layout is identical to that used by
25 MSVC.)
26
27 If you would want to use the cygwin tools to generate executables that
28 *do* use the cygwin runtime, the normal Unix configuration method
29 should work as if on Unix. But it won't produce DLLs. At least I
30 haven't succeeded in that. Also, I have no idea what changes are
31 necessary to the code for it to run successfully on cygwin.
32
33 With some work, it might be possible to use the ./configure mechanism
34 also with a "mingw32" configuration.
35
36 The following preprocessor macros are used for conditional compilation
37 related to Win32:
38
39 - G_OS_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 - G_WITH_CYGWIN is defined if compiling for the Cygwin
45   environment. Note that G_OS_WIN32 is *not* defined in that case, as
46   Cygwin is supposed to behave like Unix. Building for Cygwin is not
47   supported. Some people have presumably done it, but no changes have
48   been submitted back.
49
50 The Win32 port of GLib and related software uses only G_OS_WIN32. As
51 G_OS_WIN32 is defined in glibconfig.h, it is available to all source
52 files that use GLib (or GTk+, which uses GLib).
53
54 Additionally, there are the compiler-specific macros:
55 - __GNUC__ is defined when using GCC
56 - _MSC_VER is defined when using the Microsoft compiler
57
58 G_OS_WIN32 implies using the Microsoft C runtime MSVCRT.DLL. GLib or
59 software using it is not known to work with the older CRTDLL.DLL
60 runtime.
61
62 Building software that use GLib or GTk+
63 =======================================
64
65 Even building software that just *use* GLib or GTk+ also require to
66 have the right compiler set up the right way, so if you intend to use
67 gcc, follow the relevant instructions below in that case, too.
68
69 Pthreads library
70 ================
71
72 Before building you must get the pthreads library for Win32 from
73 http://sourceware.cygnus.com/pthreads-win32/. The pthreads-win32
74 snapshot from 1999-05-30 is the one that should be used. Edit the
75 location of the pthreads library and include files in makefile.msc or
76 makefile.mingw. The pthreads distribution includes the precompiled dll
77 and import libraries both for MSVC and gcc. Later versions might also
78 work.
79
80 The pthreads for Win32 package that the thread support uses supposedly
81 isn't quite ready yet, and thus threads stuff should not be relied
82 upon for anything serious.
83
84 Libiconv
85 ========
86
87 Before building GLib you must also have the libiconv library, either
88 from the same website mentioned above, or from it's homepage at
89 http://clisp.cons.org/~haible/packages-libiconv.html.
90
91 Where are the makefiles?
92 ========================
93
94 If you are building from a CVS snapshot, you will not have any
95 makefile.mingw or makefile.msc file. You should copy the corresponding
96 makefile.mingw.in or makefile.msc.in file to that name, and edit the
97 line that sets GLIB_VER to the correct version number.
98
99 This is done automatically when an official GLib source distribution
100 package is built.
101
102 Building GLib with gcc
103 ======================
104
105 I use the latest gcc, gcc-2.95.2. Version 2.95 will most probably also
106 work.
107
108 You can either use gcc running on cygwin, or the "pure" mingw
109 gcc. Using the latter is much easier. 
110
111 Just fetch the latest version of gcc for mingw and the msvcrt runtime,
112 currently from
113 ftp://ftp.nanotech.wisc.edu/pub/khan/gnu-win32/mingw32/snapshots/gcc-2.95.2-1/
114 .
115
116 Download the three zip archives: the gcc-<version>-msvcrt,
117 mingw-msvcrt-<timestamp> and binutils-<timestamp>-msvcrt, and unpack
118 them in a suitable directory.
119
120 Set up your PATH so that the gcc from the bin directory that got
121 created above is the one that gets used. You can skip steps 1--5
122 below. Even if you run the mingw gcc, you still want to have cygwin to
123 run make in.
124
125 If you want to run a cygwin-based gcc, it gets a bit more
126 complicated. We still want gcc to produce code that does not use
127 cygwin, but the msvcrt runtime. The way to do this can be quite
128 complex, and the instructions are not included here. Contact me if you
129 want some possibly outdated, misleading and incomplete advice.
130
131 Building with MSVC
132 ==================
133
134 If using the Microsoft toolchain, build with `nmake -f
135 makefile.msc`. Install with `nmake -f makefile.msc install`. 
136
137 --Tor Lillqvist <tml@iki.fi>