1 Tor Lillqvist <tml@iki.fi>
2 Hans Breuer <hans@breuer.org>
4 The general parts, and the stuff about gcc and autoconfiscated build
5 are by Tor Lillqvist. The stuff about MSVC build is by Hans Breuer.
10 For prebuilt binaries (DLLs and EXEs) and developer packages (headers,
11 import libraries) of GLib, GTK+, GIMP etc for Windows, surf to
12 http://www.gimp.org/win32/ . They are for "native" Windows meaning
13 they use the Win32 API and Microsoft C runtime library only, no POSIX
14 (Unix) emulation layer (like Cygwin).
16 To build GLib on Win32, you can use either gcc or the Microsoft
17 compiler and tools. Both the compiler from MSVC 5.0 and from MSVC 6.0
18 have been used successfully.
20 But note that to just *use* GLib on Windows, there is no need to build
21 it yourself. Prepackaged runtime and developer packages are available
22 from the webiste above. On Unix, it is quite normal that system admins
23 build and install libraries like GLib themselves. But on Windows
24 setting up a correct build environment can be quite a task, especially
25 if you are used to just type "./configure; make" on Unix, and expect
26 things to work as smoothly on Windows.
28 The following preprocessor macros can be used for conditional
29 compilation related to Win32 in GLib-using code:
31 - G_OS_WIN32 is defined when compiling for native Win32, without
32 any POSIX emulation, other than to the extent provided by the
33 bundled Microsoft C library (msvcrt.dll).
35 - G_WITH_CYGWIN is defined if compiling for the Cygwin
36 environment. Note that G_OS_WIN32 is *not* defined in that case, as
37 Cygwin is supposed to behave like Unix. G_OS_UNIX *is* defined when
40 - G_PLATFORM_WIN32 is defined when either G_OS_WIN32 or G_WITH_CYGWIN
43 These macros are defined in glibconfig.h, and are thus (indirectly)
44 available in all source files that include <glib.h> or GTK+ headers.
46 Additionally, there are the compiler-specific macros:
47 - __GNUC__ is defined when using gcc
48 - _MSC_VER is defined when using the Microsoft compiler
50 G_OS_WIN32 implies using the Microsoft C runtime MSVCRT.DLL. GLib is
51 not known to work with the older CRTDLL.DLL runtime, or the static
52 Microsoft C runtime libraries LIBC.LIB and LIBCMT.LIB. It apparently
53 does work with the debugging version of MSVCRT.DLL, MSVCRTD.DLL.
55 Building software that use GLib or GTK+
56 =======================================
58 Even building software that just *uses* GLib or GTK+ also require to
59 have the right compiler set up the right way, so if you intend to use
60 gcc, follow the relevant instructions below in that case, too.
62 Tor uses gcc with the -mms-bitfields flag (used to be called
63 -fnative-struct in gcc 2.x), which means that in order to use the
64 prebuilt DLLs (especially of GTK+), if you compile your code with gcc,
65 you *must* also use that flag. (This flag means that the struct layout
66 rules are identical to those used by MSVC. This is essential if the
67 same DLLs are to be usable both from gcc- and MSVC-compiled code. This
68 definitely is something one wants.)
73 Again, first decide whether you really want to do this.
75 Before building GLib you must also have the libiconv library and GNU
76 gettext. Get prebuilt binaries of libiconv (1.9.1 or newer), and
77 gettext-runtime (0.12.1 or newer) from your nearest GNU ftp mirror. If
78 you use gcc, you will also have to edit the libintl.h file from
79 gettext a tiny bit: Change the
81 # if __GNUC__ >= 2 && !defined __APPLE_CC__ && (defined __STDC__ || defined __cplusplus)
85 # if __GNUC__ >= 2 && !defined __APPLE_CC__ && !defined __MINGW32__ && (defined __STDC__ || defined __cplusplus)
89 Where are the makefiles?
90 ========================
92 If you are building from a CVS snapshot, you will not have any
93 makefile.mingw or makefile.msc files. You should copy the
94 corresponding makefile.mingw.in or makefile.msc.in file to that name,
95 and replace any @...@ strings with the correct value.
97 This is done automatically when an official GLib source distribution
98 package is built, so if you get GLib from a source distribution
99 package, there should be makefile.mingw and makefile.msc files ready
100 to use (after some editing).
102 Building GLib with gcc
103 ======================
105 Tor uses gcc 3.2. Version 2.95.3 also works.
107 You can either use gcc running on Cygwin, or the "pure" mingw
108 gcc. Using the latter might work better, or at least did at some
111 Fetch the latest version of gcc for mingw and the msvcrt runtime, from
114 Set up your PATH so that the gcc from the bin directory that got
115 created above is the one that gets used. Even if you run the mingw
116 gcc, you still want to have Cygwin to run make in.
118 Then run make -f makefile.mingw. Install the resulting DLLs somewhere
119 in your PATH. You can either keep the headers and import libraries
120 where they are, or install them somewhere else. There are no rules in
121 the makefile.mingws for installing, it is up to you where to put them.
123 Autoconfiscated build
124 =====================
126 It is also possible to use the auto*, ./configure and libtool
127 mechanism when building with gcc. You should be running Cygwin, or
128 maybe cross-compiling from real Unix, for the configure script to
129 work, obviously. It is also possible to use MSYS.
131 When building from an official source distribution, to be able to
132 build DLLs without problems, it might well be necessary to have a
133 relatively new version of libtool installed. If so, replace the
134 libtool parts included with GLib sources with newer versions by
135 running libtoolize --force. After that you want to run aclocal-1.4 and
136 autoconf before running configure.
138 Tor invokes configure using:
140 CC='gcc -mcpu=pentium3' CPPFLAGS='-I/target/include'
141 CFLAGS=-O3 LDFLAGS='-L/target/lib' ./configure --with-libiconv
142 --disable-static --prefix=/target --host=i386-pc-mingw32
144 (on a single line). The /target/include mentioned contains the header
145 files for libintl and libiconv, and the (import) libraries are in
146 /target/lib. This happens to be in the same tree where he configures
147 GLib to be installed, but doesn't have to be.
149 Please note that the ./configure mechanism should not blindly be used
150 to build a GLib to be distributed to other developers because it
151 produces a compiler-dependent glibconfig.h (and config.h, but that
152 shouldn't matter, as it isn't seen by GLib-using applications). For
153 instance, the typedef for gint64 is long long with gcc, but __int64
156 Except for this and a few other minor issues, there really shouldn't
157 be any reason to distribute separate GLib headers and DLLs for gcc and
158 MSVC users, as the compilers generate code that uses the same C
159 runtime library, and is mutually binary compatible. Thus one either
160 has to manually edit glibconfig.h afterwards, or use the supplied
161 glibconfig.h.win32. This has been produced by running configure twice,
162 once using gcc and once using MSVC, and merging the resulting files
165 The hand-written makefile.{mingw,msc} files, and the stuff in the
166 "build" subdirectory, produce DLLs and import libraries that match
167 what Makefile.am and libtool produces. For GLib, the DLL is called
168 libglib-2.0-0.dll, and the import libraries libglib-2.0.dll.a and
169 glib-2.0.lib. Note that the "2.0" is part of the "basename" of the
170 library, it is not something that libtool has tucked on. The -0 suffix
171 is the value of "LT_CURRENT - LT_AGE". The 0 is *not* simply the micro
172 version number of GLib, although, for GLib 2.2.0, it happens to be the
173 same. The LT_CURRENT - LT_AGE value will on purpose be kept as zero as
174 long as binary compatibility is maintained. For the gory details, see
175 configure.in and libtool documentation.
177 If you want to run the Cygwin-hosted gcc, and still want to produce
178 code that does not use Cygwin, but the msvcrt runtime, in theory it
179 should work to use the -no-cygwin flag, but Tor hasn't tested that
182 If you would want to use the Cygwin tools to generate a GLib that
183 *does* use the Cygwin runtime, the normal Unix configuration method
184 should work as if on Unix. Note that successfully producing shared
185 libraries (DLLs) for Cygwin most probably requires you to have a very
186 new libtool. (And a new libtool probably requires rather new autoconf
187 and automake.) Tor hasn't tested this in a while, either.
192 All the MSVC makefiles are for the command line build with nmake. If
193 you want to use the VC-UI you can simply create wrapper .dsp makefiles
194 (read the VC docs how to do so).
196 Some modules may require Perl to auto-generate files. The goal (at
197 least Hans's) is to not require any more tools.
201 nmake -f makefile.msc
203 nmake -f makefile.msc DEBUG=1
206 The former will create 'release' versions of the DLLs. If you
207 plan to distribute you DLLs please use this command. The latter
208 will create DLLs with debug information _and_ link them with
209 msvcrtd.dll instead of msvcrt.dll.
210 Beware: There are known problems with mixing DLLs in one
211 application, which are build against different runtimes.
212 Especially the index-to-file mapping used by 'unix-style' file
213 operation - _open() _pipe() etc. - breaks sometimes in strange
214 ways (for example the Gimp plug-in communication).
217 Required libraries (not build from cvs)
219 libintl (gnu-intl), libiconv
220 libtiff, libpng, zlib, libjpeg
222 are available pre-built from the website mentioned above.
226 Instead of the Unix and auto* way of tracking versions and resolving
227 dependencies (configure; make; make install) involving autoconf,
228 automake, libtool and friends the MSVC build uses a different
231 The core of it's versioning is the file build/win32/module.defs.
232 It contains entries of the form MODULE_VER, e.g.:
237 and the placement of these modules defined as MODULE, e.g.:
240 LIBICONV = $(TOP)/libiconv-$(LIBICONV_VER)
242 whereas TOP is defined as the relative path from the respective
243 module directory to your top build directory. Every makefile.msc
244 needs to define TOP before including the common make file part
245 make.msc, which than includes module.defs, like:
248 !INCLUDE $(TOP)/glib/build/win32/make.msc
250 (Taken from gtk+/gdk/makefile.msc)
252 With this provision it is possible to create almost placement
253 independent makefiles without requiring to 'install' the libraries and
254 headers into a common place (as it is done on Unix, and as Tor does
255 when producing his zipfiles with prebuilt GLib, GTK+ etc).
259 config.h.win32.in : @XXX_MAJOR_VERSION@ needs to be replaced by
260 the current version/build number. The resulting file is to be saved
261 as 'config.h.win32'. This should be automatically done if a package
262 gets build on the Unix platform.
264 makefile.msc.in : @XXX_MAJOR_VERSION@ to be replaced. Save as
267 <module>.def : every function which should be used from the outside of
268 a dll needs to be marked for 'export'. It is common that one needs to change
269 these files after some api changes occured. If there are variables to be
270 exported another mechanism is needed, like :
273 # ifdef GDK_COMPILATION
274 # define GDKVAR __declspec(dllexport)
276 # define GDKVAR extern __declspec(dllimport)
279 # define GDKVAR extern
286 all modules should be build in a common directory tree otherwise you
287 need to adapt the file 'module.defs'. They are listed here in increasing
290 <common rootdir without spaces>
294 | +- build : [this module lives in the cvs root dir]
296 | | .\module.defs : defines (relative) locations of the headers
297 | | and libs and version numbers to be include
299 | | .\make.msc : include by almost every 'makefile.msc'
301 | | .\README.WIN32 : more information how to build
302 | | .\glibconfig.h.win32.in : similar to config.h.win32.in
303 | | .\makefile.msc : master makefile, sub dir makefiles should work
307 | +- gthread : does _not_ depend on pthread anymore
311 | +- pango : 'native' build does not require extra libs and
312 | | includes the minimal required text renderer
313 | | (there is also a currently slightly broken FreeType2
314 | | based implementation for win32)
315 | +- modules (not yet build)
319 | .\makefile.msc : build here
322 | | .\config.h.win32 : for all the below
325 | | .\gdk_pixbuf.rc.in : version resource for the DLLs. Needs
326 | | to be converted (filled with version info)
327 | | as described above.
330 | | | .\makefile.msc : some auto-generation is needed to build in the
331 | | | in the subdirectory
338 | .\makefile.msc : master makefile to build The Gimp. The makefiles
339 | from the sub dirs should work stand alone, but than
340 | the user needs to know the build order
343 +- dia : additionally depends on libart_lgpl (in cvs)
344 | and libxml2 ( see http://www.xmlsoft.org/ )