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 on Unix just type ./configure; make, 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 -fnative-struct flag, which means that in order to
63 use the prebuilt DLLs (especially of GTK+), you *must* also use that
64 flag. (This flag means that the struct layout rules are identical to
65 those used by MSVC. This is essential if the same DLLs are to be
66 usable both from gcc- and MSVC-compiled code. This definitely is
72 Again, first decide whether you really want to do this.
74 Before building GLib you must also have the libiconv library, either
75 from the same website mentioned above, or from it's homepage at
76 http://clisp.cons.org/~haible/packages-libiconv.html. Libiconv has
77 makefiles for building with MS Visual C only, but as it is one source
78 file only, building it "by hand" with gcc isn't hard.
80 You must also have the "intl" library from GNU tettext 0.10.40 (or
81 later). Get a prebuilt version from the website mentioned above.
83 Edit the correct paths to those libraries in build/win32/module.defs
86 Where are the makefiles?
87 ========================
89 If you are building from a CVS snapshot, you will not have any
90 makefile.mingw or makefile.msc files. You should copy the
91 corresponding makefile.mingw.in or makefile.msc.in file to that name,
92 and replace any @...@ strings with the correct value.
94 This is done automatically when an official GLib source distribution
95 package is built, so if you get GLib from a source distribution
96 package, there should be makefile.mingw and makefile.msc files ready
97 to use (after some editing).
99 Building GLib with gcc
100 ======================
102 Tor uses gcc-2.95.3. Version 2.95.2 will most probably also work.
104 You can either use gcc running on Cygwin, or the "pure" mingw
105 gcc. Using the latter might work better, or at least did at some
108 Fetch the latest version of gcc for mingw and the msvcrt runtime, from
111 Set up your PATH so that the gcc from the bin directory that got
112 created above is the one that gets used. Even if you run the mingw
113 gcc, you still want to have Cygwin to run make in.
115 Then run make -f makefile.mingw. Install the resulting DLLs somewhere
116 in your PATH. You can either keep the headers and import libraries
117 where they are, or install them somewhere else. There are no rules in
118 the makefile.mingws for installing, it is up to you where to put them.
120 Autoconfiscated build
121 =====================
123 It is also possible to use the auto*, ./configure and libtool
124 mechanism when building with gcc. You should be running Cygwin, or
125 maybe cross-compiling from real Unix, for the configure script to
126 work, obviously. (It might also be possible to use "MSYS", but I
127 haven't checked.) You most probably should have very new auto* and
128 libtool. Tor invokes configure using:
130 CC='gcc -mpentium -fnative-struct'
131 CPPFLAGS='-I/src/libiconv-1.7/include -I/target/include'
132 LDFLAGS='-L/src/libiconv-1.7/lib -L/target/lib' ./configure
133 --with-libiconv --disable-static --prefix=/target
134 --host=i386-pc-mingw32 --enable-maintainer-mode
138 But please note that the ./configure mechanism should not blindly be
139 used to build a GLib to be distributed to other developers because it
140 produces a compiler-dependent glibconfig.h (and config.h, but that
141 shouldn't matter, as it isn't seen by GLib-using applications). For
142 instance, the typedef for gint64 is long long with gcc, but __int64
145 Except for this and a few other minor issues, there really shouldn't
146 be any reason to distribute separate GLib headers and DLLs for gcc and
147 MSVC users, as both compilers generate code that uses the same C
148 runtime library. Thus one either has to manually edit glibconfig.h
149 afterwards, or use the supplied config.h.win32 and
150 glibconfig.h.win32. These have been produced by running configure
151 twice, once using gcc and once using MSVC, and merging the resulting
154 There might be other hickups when using auto* and configure to build
155 with gcc. Lately Tor has used auto*/configure/libtool exclusively when
156 building GLib, GTK+, GIMP etc on Win32, and it seems to work well
157 (with some patches applied to the current CVS libtool...).
159 The hand-written makefile.{mingw,msc} files, and the stuff in the
160 "build" subdirectory, produce DLLs and import libraries that match
161 what Makefile.am and libtool produces. For GLib, the DLL is called
162 libglib-1.3-15.dll (at GLib 1.3.15), and the import libraries
163 libglib-1.3.dll.a and glib-1.3.lib. Note that the "1.3" is part of the
164 "basename" of the library, it is not something that libtool have
165 tucked on. The -15 suffix is the value of "LT_CURRENT - LT_AGE". The
166 15 is *not* simply the micro version number of GLib, although, for
167 GLib 1.3.15, it happens to be the same. For the gory details, see
168 configure.in and libtool documentation.
170 If you want to run the Cygwin-hosted gcc, and still want to produce
171 code that does not use Cygwin, but the msvcrt runtime, in theory it
172 should work to use the -no-cygwin flag, but Tor hasn't tested that
175 If you would want to use the Cygwin tools to generate a GLib that
176 *does* use the Cygwin runtime, the normal Unix configuration method
177 should work as if on Unix. Note that successfully producing shared
178 libraries (DLLs) for Cygwin most probably requires you to have a very
179 new libtool. (And a new libtool probably requires rather new autoconf
180 and automake.) Tor hasn't tested this in a while.
185 All the MSVC makefiles are for the command line build with nmake.
186 If you want to use the VC-UI you can simply create wrapper .dsp
187 makefiles (read the VC docs how to do so).
189 Some modules may require Perl to auto-generate files. The goal (at
190 least Hans's) is to not require any more tools.
194 nmake -f makefile.msc
196 nmake -f makefile.msc DEBUG=1
199 The former will create 'release' versions of the DLLs. If you
200 plan to distribute you DLLs please use this command. The latter
201 will create DLLs with debug information _and_ link them with
202 msvcrtd.dll instead of msvcrt.dll.
203 Beware: There are known problems with mixing DLLs in one
204 application, which are build against different runtimes.
205 Especially the index-to-file mapping used by 'unix-style' file
206 operation - _open() _pipe() etc. - breaks sometimes in strange
207 ways (for example the Gimp plug-in communication).
210 Required libraries (not build from cvs)
212 libintl (gnu-intl), libiconv
213 libtiff, libpng, zlib, libjpeg
215 are available pre-built from the website mentioned above.
219 Instead of the Unix and auto* way of tracking versions and resolving
220 dependencies (configure; make; make install) involving autoconf,
221 automake, libtool and friends the MSVC build uses a different
224 The core of it's versioning is the file build/win32/module.defs.
225 It contains entries of the form MODULE_VER, e.g.:
230 and the placement of these modules defined as MODULE, e.g.:
233 LIBICONV = $(TOP)/libiconv-$(LIBICONV_VER)
235 whereas TOP is defined as the relative path from the respective
236 module directory to your top build directory. Every makefile.msc
237 needs to define TOP before including the common make file part
238 make.msc, which than includes module.defs, like:
241 !INCLUDE $(TOP)/glib/build/win32/make.msc
243 (Taken from gtk+/gdk/makefile.msc)
245 With this provision it is possible to create almost placement
246 independent makefiles without requiring to 'install' the libraries and
247 headers into a common place (as it is done on Unix, and as Tor does
248 when producing his zipfiles with prebuilt GLib, GTK+ etc).
252 config.h.win32.in : @XXX_MAJOR_VERSION@ needs to be replaced by
253 the current version/build number. The resulting file is to be saved
254 as 'config.h.win32'. This should be automatically done if a package
255 gets build on the Unix platform.
257 makefile.msc.in : @XXX_MAJOR_VERSION@ to be replaced. Save as
260 <module>.def : every function which should be used from the outside of
261 a dll needs to be marked for 'export'. It is common that one needs to change
262 these files after some api changes occured. If there are variables to be
263 exported another mechanism is needed, like :
266 # ifdef GDK_COMPILATION
267 # define GDKVAR __declspec(dllexport)
269 # define GDKVAR extern __declspec(dllimport)
272 # define GDKVAR extern
279 all modules should be build in a common directory tree otherwise you
280 need to adapt the file 'module.defs'. They are listed here in increasing
283 <common rootdir without spaces>
287 | +- build : [this module lives in the cvs root dir]
289 | | .\module.defs : defines (relative) locations of the headers
290 | | and libs and version numbers to be include
292 | | .\make.msc : include by almost every 'makefile.msc'
294 | | .\README.WIN32 : more information how to build
295 | | .\glibconfig.h.win32.in : similar to config.h.win32.in
296 | | .\makefile.msc : master makefile, sub dir makefiles should work
300 | +- gthread : does _not_ depend on pthread anymore
304 | +- pango : 'native' build does not require extra libs and
305 | | includes the minimal required text renderer
306 | | (there is also a currently slightly broken FreeType2
307 | | based implementation for win32)
308 | +- modules (not yet build)
312 | .\makefile.msc : build here
315 | | .\config.h.win32 : for all the below
318 | | .\gdk_pixbuf.rc.in : version resource for the DLLs. Needs
319 | | to be converted (filled with version info)
320 | | as described above.
323 | | | .\makefile.msc : some auto-generation is needed to build in the
324 | | | in the subdirectory
331 | .\makefile.msc : master makefile to build The Gimp. The makefiles
332 | from the sub dirs should work stand alone, but than
333 | the user needs to know the build order
336 +- dia : additionally depends on libart_lgpl (in cvs)
337 | and libxml2 ( see http://www.xmlsoft.org/ )