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