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/downloads.html . They are for "native"
13 Windows meaning they use the Win32 API and Microsoft C runtime library
14 only, no POSIX (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 without bothering to
24 look for prebuilt packages, especially if prebuilt packages tend to
25 use installation paths that don't conform to local customs.
27 On Windows setting up a correct build environment can be quite a task,
28 especially if you are used to just type "./configure; make" on Unix,
29 and expect things to work as smoothly on Windows.
31 The following preprocessor macros are to be used for conditional
32 compilation related to Win32 in GLib-using code:
34 - G_OS_WIN32 is defined when compiling for native Win32, without
35 any POSIX emulation, other than to the extent provided by the
36 bundled Microsoft C library (msvcrt.dll).
38 - G_WITH_CYGWIN is defined if compiling for the Cygwin
39 environment. Note that G_OS_WIN32 is *not* defined in that case, as
40 Cygwin is supposed to behave like Unix. G_OS_UNIX *is* defined when
43 - G_PLATFORM_WIN32 is defined when either G_OS_WIN32 or G_WITH_CYGWIN
46 These macros are defined in glibconfig.h, and are thus (indirectly)
47 available in all source files that include <glib.h> or GTK+ headers.
49 Additionally, there are the compiler-specific macros:
50 - __GNUC__ is defined when using gcc
51 - _MSC_VER is defined when using the Microsoft compiler
53 G_OS_WIN32 implies using the Microsoft C runtime MSVCRT.DLL. GLib is
54 not known to work with the older CRTDLL.DLL runtime, or the static
55 Microsoft C runtime libraries LIBC.LIB and LIBCMT.LIB. It apparently
56 does work with the debugging version of MSVCRT.DLL,
57 MSVCRTD.DLL. Presumably, if compiled with MSVC.NET, it also works with
58 MSVCR70.DLL. Please note that it's dubious if you would be allowed by
59 the license to distrubute a GLib linked to MSVCR70.DLL, as it is not
60 part of the operating system, but of the MSVC product. MSVCRT.DLL is
63 Building software that use GLib or GTK+
64 =======================================
66 Even building software that just *uses* GLib or GTK+ also require to
67 have the right compiler set up the right way, so if you intend to use
68 gcc, follow the relevant instructions below in that case, too.
70 Tor uses gcc with the -mms-bitfields flag (used to be called
71 -fnative-struct in gcc 2.x), which means that in order to use the
72 prebuilt DLLs (especially of GTK+), if you compile your code with gcc,
73 you *must* also use that flag. This flag means that the struct layout
74 rules are identical to those used by MSVC. This is essential if the
75 same DLLs are to be usable both from gcc- and MSVC-compiled code. This
76 definitely is something one wants.
81 Again, first decide whether you really want to do this.
83 Before building GLib you must also have the libiconv library and GNU
84 gettext. Get prebuilt binaries of libiconv (1.9.1 or newer), and
85 gettext-runtime (0.13.1 or newer) from www.gimp.org/win32/downloads.html.
87 Autoconfiscated build (with gcc)
88 ================================
90 Tor uses gcc 3.2. Version 2.95.3 also works.
92 You can either use gcc running on Cygwin, or the "pure" mingw
93 gcc. Using the latter might work better, or at least did at some
94 point. You should be running Cygwin, or maybe cross-compiling from
95 real Unix, for the configure script to work, obviously. It is also
98 If you want to use mingw's gcc, install gcc, Win32 headers and
99 binutils from www.mingw.org. Set up your PATH so that the mingw gcc is
100 the one that gets used, and not Cygwin's gcc. Even if you run the
101 mingw gcc, you still want to have Cygwin to run make in.
103 Tor invokes configure using:
105 CC='gcc -mcpu=pentium3' CPPFLAGS='-I/target/include'
106 CFLAGS=-O3 LDFLAGS='-L/target/lib' ./configure --with-libiconv
107 --disable-gtk-doc --prefix=/target --host=i386-pc-mingw32
109 (on a single line). The /target/include mentioned contains the header
110 files for libintl and libiconv, and the (import) libraries are in
111 /target/lib. This happens to be in the same tree where he configures
112 GLib to be installed, but doesn't have to be.
114 Please note that the ./configure mechanism should not blindly be used
115 to build a GLib to be distributed to other developers because it
116 produces a compiler-dependent glibconfig.h (and config.h, but that
117 shouldn't matter, as it isn't seen by GLib-using applications). For
118 instance, the typedef for gint64 is long long with gcc, but __int64
121 Except for this and a few other minor issues, there really shouldn't
122 be any reason to distribute separate GLib headers and DLLs for gcc and
123 MSVC users, as the compilers generate code that uses the same C
124 runtime library. The DLL generated by either compiler is binary
125 compatible with the other one. Thus one either has to manually edit
126 glibconfig.h afterwards, or use the supplied glibconfig.h.win32 which
127 has been produced by running configure twice, once using gcc and once
128 using MSVC, and merging the resulting files with diff -D.
130 For GLib, the DLL is called
131 libglib-2.0-0.dll, and the import libraries libglib-2.0.dll.a and
132 glib-2.0.lib. Note that the "2.0" is part of the "basename" of the
133 library, it is not something that libtool has tucked on. The -0 suffix
134 is the value of "LT_CURRENT - LT_AGE". The 0 is *not* simply the micro
135 version number of GLib, although, for GLib 2.2.0, it happens to be the
136 same. The LT_CURRENT - LT_AGE value will on purpose be kept as zero as
137 long as binary compatibility is maintained. For the gory details, see
138 configure.in and libtool documentation.
140 If you want to run the Cygwin-hosted gcc, and still want to produce
141 code that does not use Cygwin, but the msvcrt runtime, in theory it
142 should work to use the -no-cygwin flag, but Tor hasn't tested that
145 If you would want to use the Cygwin tools to generate a GLib that
146 *does* use the Cygwin runtime, the normal Unix configuration method
147 should work as if on Unix. Note that successfully producing shared
148 libraries (DLLs) for Cygwin most probably requires you to have a very
149 new libtool. (And a new libtool probably requires rather new autoconf
150 and automake.) Tor hasn't tested this in a while, either.
155 If you are building from a CVS snapshot, you will not have any
156 makefile.msc files. You should copy the corresponding makefile.msc.in
157 file to that name, and replace any @...@ strings with the correct
160 This is done automatically when an official GLib source distribution
161 package is built, so if you get GLib from a source distribution
162 package, there should be makefile.msc files ready to use (after some
165 The hand-written makefile.msc files, and the stuff in the "build"
166 subdirectory, produce DLLs and import libraries that match what the
167 so-called autoconfiscated build produces.
169 All the MSVC makefiles are for the command line build with nmake. If
170 you want to use the VC-UI you can simply create wrapper .dsp makefiles
171 (read the VC docs how to do so).
173 Some modules may require Perl to auto-generate files. The goal (at
174 least Hans's) is to not require any more tools.
178 nmake -f makefile.msc
180 nmake -f makefile.msc DEBUG=1
183 The former will create 'release' versions of the DLLs. If you
184 plan to distribute you DLLs please use this command. The latter
185 will create DLLs with debug information _and_ link them with
186 msvcrtd.dll instead of msvcrt.dll.
187 Beware: There are known problems with mixing DLLs in one
188 application, which are build against different runtimes.
189 Especially the index-to-file mapping used by 'unix-style' file
190 operation - _open() _pipe() etc. - breaks sometimes in strange
191 ways (for example the Gimp plug-in communication).
194 Required libraries (not build from cvs)
196 libintl (gnu-intl), libiconv
197 libtiff, libpng, zlib, libjpeg
199 are available pre-built from the website mentioned above.
203 Instead of the Unix and auto* way of tracking versions and resolving
204 dependencies (configure; make; make install) involving autoconf,
205 automake, libtool and friends the MSVC build uses a different
208 The core of it's versioning is the file build/win32/module.defs.
209 It contains entries of the form MODULE_VER, e.g.:
214 and the placement of these modules defined as MODULE, e.g.:
217 LIBICONV = $(TOP)/libiconv-$(LIBICONV_VER)
219 whereas TOP is defined as the relative path from the respective
220 module directory to your top build directory. Every makefile.msc
221 needs to define TOP before including the common make file part
222 make.msc, which than includes module.defs, like:
225 !INCLUDE $(TOP)/glib/build/win32/make.msc
227 (Taken from gtk+/gdk/makefile.msc)
229 With this provision it is possible to create almost placement
230 independent makefiles without requiring to 'install' the libraries and
231 headers into a common place (as it is done on Unix, and as Tor does
232 when producing his zipfiles with prebuilt GLib, GTK+ etc).
236 config.h.win32.in : @XXX_MAJOR_VERSION@ needs to be replaced by
237 the current version/build number. The resulting file is to be saved
238 as 'config.h.win32'. This should be automatically done if a package
239 gets build on the Unix platform.
241 makefile.msc.in : @XXX_MAJOR_VERSION@ to be replaced. Save as
244 <module>.def : every function which should be used from the outside of
245 a dll needs to be marked for 'export'. It is common that one needs to change
246 these files after some api changes occured. If there are variables to be
247 exported another mechanism is needed, like :
250 # ifdef GDK_COMPILATION
251 # define GDKVAR __declspec(dllexport)
253 # define GDKVAR extern __declspec(dllimport)
256 # define GDKVAR extern
263 all modules should be build in a common directory tree otherwise you
264 need to adapt the file 'module.defs'. They are listed here in increasing
267 <common rootdir without spaces>
271 | +- build : [this module lives in the cvs root dir]
273 | | .\module.defs : defines (relative) locations of the headers
274 | | and libs and version numbers to be include
276 | | .\make.msc : include by almost every 'makefile.msc'
278 | | .\README.WIN32 : more information how to build
279 | | .\glibconfig.h.win32.in : similar to config.h.win32.in
280 | | .\makefile.msc : master makefile, sub dir makefiles should work
284 | +- gthread : does _not_ depend on pthread anymore
288 | +- pango : 'native' build does not require extra libs and
289 | | includes the minimal required text renderer
290 | | (there is also a currently slightly broken FreeType2
291 | | based implementation for win32)
292 | +- modules (not yet build)
296 | .\makefile.msc : build here
299 | | .\config.h.win32 : for all the below
302 | | .\gdk_pixbuf.rc.in : version resource for the DLLs. Needs
303 | | to be converted (filled with version info)
304 | | as described above.
307 | | | .\makefile.msc : some auto-generation is needed to build in the
308 | | | in the subdirectory
315 | .\makefile.msc : master makefile to build The Gimp. The makefiles
316 | from the sub dirs should work stand alone, but than
317 | the user needs to know the build order
320 +- dia : additionally depends on libart_lgpl (in cvs)
321 | and libxml2 ( see http://www.xmlsoft.org/ )