b3c3ad069e88aa6ce2ef4cf092a9801dfd90b327
[platform/upstream/glib.git] / README.win32
1 General
2 =======
3
4 For prebuilt binaries (DLLs and EXEs) and developer packages (headers,
5 import libraries) of GLib, GTK+, GIMP etc for Windows, surf to
6 http://www.gimp.org/win32/ . They are for "native" Windows meaning
7 they use the Win32 API and Microsoft C runtime library only, no POSIX
8 (Unix) emulation layer (like Cygwin). 
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 yourself. Prepackaged runtime and developer packages are available
16 from the webiste above. On Unix, it is quite normal that system admins
17 build and install libraries like GLib themselves. But on Windows
18 setting up a correct build environment can be quite a task, especially
19 if you are used to on Unix just type ./configure; make, and expect
20 things to work as smoothly on Windows.
21
22 The following preprocessor macros can be used for conditional
23 compilation related to Win32 in GLib-using code:
24
25 - G_OS_WIN32 is defined when compiling for native Win32, without
26   any POSIX emulation, other than to the extent provided by the
27   bundled Microsoft C library (msvcrt.dll).
28
29 - G_WITH_CYGWIN is defined if compiling for the Cygwin
30   environment. Note that G_OS_WIN32 is *not* defined in that case, as
31   Cygwin is supposed to behave like Unix. G_OS_UNIX *is* defined when
32   compiling for Cygwin.
33
34 - G_PLATFORM_WIN32 is defined when either G_OS_WIN32 or G_WITH_CYGWIN
35   is defined.
36
37 These macros are defined in glibconfig.h, and are thus (indirectly)
38 available in all source files that include <glib.h> or GTK+ headers.
39
40 Additionally, there are the compiler-specific macros:
41 - __GNUC__ is defined when using gcc
42 - _MSC_VER is defined when using the Microsoft compiler
43
44 G_OS_WIN32 implies using the Microsoft C runtime MSVCRT.DLL. GLib is
45 not known to work with the older CRTDLL.DLL runtime, or the static
46 Microsoft C runtime libraries LIBC.LIB and LIBCMT.LIB. It apparently
47 does work with the debugging version of MSVCRT.DLL, MSVCRTD.DLL.
48
49 Building software that use GLib or GTK+
50 =======================================
51
52 Even building software that just *uses* GLib or GTK+ also require to
53 have the right compiler set up the right way, so if you intend to use
54 gcc, follow the relevant instructions below in that case, too.
55
56 I use gcc with the -fnative-struct flag, which means that in order to
57 use the prebuilt DLLs (especially of GTK+), you *must* also use that
58 flag. (This flag means that the struct layout rules are identical to
59 those used by MSVC. This is essential if the same DLLs are to be
60 usable both from gcc- and MSVC-compiled code. This definitely is
61 something one wants.)
62
63 Building GLib
64 =============
65
66 Again, first decide whether you really want to do this.
67
68 Before building GLib you must also have the libiconv library, either
69 from the same website mentioned above, or from it's homepage at
70 http://clisp.cons.org/~haible/packages-libiconv.html. Libiconv has
71 makefiles for building with MS Visual C only, but as it is one source
72 file only, building it "by hand" with gcc isn't hard.
73
74 You must also have the "intl" library from GNU tettext 0.10.40 (or
75 later). Get a prebuilt version from the website mentioned above.
76
77 Edit the correct paths to those libraries in build/win32/module.defs
78 as appropriate.
79
80 Where are the makefiles?
81 ========================
82
83 If you are building from a CVS snapshot, you will not have any
84 makefile.mingw or makefile.msc files. You should copy the
85 corresponding makefile.mingw.in or makefile.msc.in file to that name,
86 and replace any @...@ strings with the correct value.
87
88 This is done automatically when an official GLib source distribution
89 package is built, so if you get GLib from a source distribution
90 package, there should be makefile.mingw and makefile.msc files ready
91 to use (after some editing).
92
93 Building GLib with gcc
94 ======================
95
96 I use gcc-2.95.3. Version 2.95.2 will most probably also work.
97
98 You can either use gcc running on Cygwin, or the "pure" mingw
99 gcc. Using the latter might work better, or at least did at some
100 point.
101
102 Fetch the latest version of gcc for mingw and the msvcrt runtime, from
103 www.mingw.org.
104
105 Set up your PATH so that the gcc from the bin directory that got
106 created above is the one that gets used. Even if you run the mingw
107 gcc, you still want to have Cygwin to run make in.
108
109 Then run make -f makefile.mingw. Install the resulting DLLs somewhere
110 in your PATH. You can either keep the headers and import libraries
111 where they are, or install them somewhere else. There are no rules in
112 the makefile.mingws for installing, it is up to you where to put them.
113
114 Autoconfiscated build
115 =====================
116
117 It is also possible to use the auto*, ./configure and libtool
118 mechanism when building with gcc. You should be running Cygwin, or
119 maybe cross-compiling from real Unix, for the configure script to
120 work, obviously. (It might also be possible to use "MSYS", but I
121 haven't checked.) You most probably should have very new auto* and
122 libtool. Personally, I invoke configure using:
123
124 CC='gcc -mpentium -fnative-struct'
125   CPPFLAGS='-I/src/libiconv-1.7/include -I/target/include'
126   LDFLAGS='-L/src/libiconv-1.7/lib -L/target/lib' ./configure
127   --with-libiconv --disable-static --prefix=/target
128   --host=i386-pc-mingw32 --enable-maintainer-mode
129
130 (on a single line)
131
132 But please note that the ./configure mechanism should not blindly be
133 used to build a GLib to be distributed to other developers because it
134 produces a compiler-dependent glibconfig.h (and config.h, but that
135 shouldn't matter, as it isn't seen by GLib-using applications). For
136 instance, the typedef for gint64 is long long with gcc, but __int64
137 with MSVC.
138
139 Except for this and a few other minor issues, there really shouldn't
140 be any reason to distribute separate GLib headers and DLLs for gcc and
141 MSVC users, as both compilers generate code that uses the same C
142 runtime library. Thus one either has to manually edit glibconfig.h
143 afterwards, or use the supplied config.h.win32 and
144 glibconfig.h.win32. These have been produced by running configure
145 twice, once using gcc and once using MSVC, and merging the resulting
146 files with diff -D.
147
148 There might be other hickups when using auto* and configure to build
149 with gcc. Lately I have used auto*/configure/libtool exclusively when
150 building GLib, GTK+, GIMP etc on Win32, and it seems to work well
151 (with some patches applied to the current CVS libtool...).
152
153 The hand-written makefile.{mingw,msc} files, and the stuff in the
154 "build" subdirectory, produce DLLs and import libraries that match
155 what Makefile.am and libtool produces. For GLib, the DLL is called
156 libglib-1.3-15.dll (at GLib 1.3.15), and the import libraries
157 libglib-1.3.dll.a and glib-1.3.lib. Note that the "1.3" is part of the
158 "basename" of the library, it is not something that libtool have
159 tucked on. The -15 suffix is the value of "LT_CURRENT - LT_AGE". The
160 15 is *not* simply the micro version number of GLib, although, for
161 GLib 1.3.15, it happens to be the same. For the gory details, see
162 configure.in and libtool documentation.
163
164 If you want to run the Cygwin-hosted gcc, and still want to produce
165 code that does not use Cygwin, but the msvcrt runtime, in theory it
166 should work to use the -no-cygwin flag, but I haven't tested that
167 lately.
168
169 If you would want to use the Cygwin tools to generate a GLib that
170 *does* use the Cygwin runtime, the normal Unix configuration method
171 should work as if on Unix. Note that successfully producing shared
172 libraries (DLLs) for Cygwin most probably requires you to have a very
173 new libtool. (And a new libtool probably requires rather new autoconf
174 and automake.) I haven't personally tested this in a while.
175
176 Building with MSVC
177 ==================
178
179 If using the Microsoft toolchain, build with `nmake -f
180 makefile.msc`.
181
182 --Tor Lillqvist <tml@iki.fi>