4 For more information about the port or GLib, GTk+ and the GIMP to
5 native Windows, and pre-built binary packages, see
6 http://www.iki.fi/tml/gimp/win32/ . "Native" means that we use the
7 Win32 API only, and not any POSIX emulation layer except that provided
8 by the Microsoft runtime C library. Additionally, a pthreads emulation
11 To build GLib on Win32, you can use either the Microsoft compiler and
12 tools, or gcc. Both the compiler from MSVC 5.0 and from MSVC 6.0 have
13 been used successfully. With gcc I mean gcc-2.95 or gcc-2.95.2 as
14 distributed by Mumit Khan, either as a mingw version (preferred), or
15 running under cygwin. To successfully use gcc, follow the instructions
16 below. We want to use gcc -mno-cygwin, i.e. produce executables (.exe
17 and .dll files) that do *not* require the cygwin runtime library. This
20 To test the GLib functions, go to the tests subdirectory and enter
21 `nmake -f makefile.msc check` or `make -f makefile.cygwin check`.
23 If you would want to use the cygwin tools to generate executables that
24 *do* use the cygwin runtime, the normal Unix configuration method
25 should work as if on Unix. But it won't produce DLLs. At least I
26 haven't succeeded in that.
28 With a little work, it might be possible to use the ./configure
29 mechanism also with a "mingw32" configuration.
31 The following preprocessor macro are used for conditional compilation
34 - G_OS_WIN32 is defined when compiling for Win32, *and* without
35 any POSIX emulation, other that to the extent provided by the
36 bundled Microsoft C library (msvcrt.dll) and the pthreads-win32
37 library. For instance, pathnames are in the native Windows syntax.
39 - _WIN32 is defined by the compiler
41 The Win32 port uses the combination with both of those on. As
42 G_OS_WIN32 is defined in glibconfig.h, it is available to all source
43 files that use GLib (or GTk+, which uses GLib).
45 Additionally, there are the compiler-specific macros:
46 - _MSC_VER is defined when using the Microsoft compiler
47 - __GNUC__ is defined when using GCC
49 Some of the usage of these macros used to be a bit mixed up, and had
50 to be straightened out when adding the gcc support. In particular, I
51 used to check for _MSC_VER in some places where I really wanted to
52 check for the Microsoft C library, and those checks has now been
53 changed to G_OS_WIN32.
55 G_OS_WIN32 implies using the Microsoft C runtime MSVCRT.DLL.
57 Building software that use GLib or GTk+
58 =======================================
60 Unfortunately, even building software that just *use* GLib or GTk+
61 also require to have the right compiler set up the right way, so if
62 you intend to use gcc, follow the relevant instructions below in that
68 Before building you must get the pthreads library for Win32 from
69 http://sourceware.cygnus.com/pthreads-win32/. The pthreads-win32
70 snapshot from 1999-05-30 is the one that should be used. Edit the
71 location of the pthreads library and include files in makefile.msc or
72 makefile.cygwin. The pthreads distribution includes the precompiled dll
73 and import libraries both for MSVC and gcc.
75 The pthreads for Win32 package that the thread support uses supposedly
76 isn't quite ready yet, and thus threads stuff should not be relied
77 upon for anything serious.
79 Where are the makefiles?
80 ========================
82 If you are building from a CVS snapshot, you will not have any
83 makefile.msc or makefile.cygwin file. You should copy the
84 corresponding makefile.msc.in or makefile.cygwin.in file to that name,
85 and edit the line that sets GLIB_VER to the correct version number.
87 This is done automatically when an official distribution package is
93 If using the Microsoft toolchain, build with `nmake -f
94 makefile.msc`. Install with `nmake -f makefile.msc install`.
99 I use the latest and greatest gcc, gcc-2.95.2. 2.95 will also work.
100 Earlier version might, but you are on your own.
102 You can either use gcc running on cygwin, or the "pure" mingw
103 gcc. Using the latter is much easier. Just fetch the latest version of
104 gcc for mingw and the msvcrt runtime, currently from
105 ftp://ftp.nanotech.wisc.edu/pub/khan/gnu-win32/mingw32/snapshots/gcc-2.95.2-1/
106 . Download the three zip archives: the gcc-<version>-msvcrt,
107 mingw-msvcrt-<timestamp> and binutils-<timestamp>-msvcrt, and unpack
108 them in a suitable directory. Set up your PATH so that the gcc from
109 the bin directory that got created above is the one that gets
110 used. You can skip steps 1--5 below. Even if you run the mingw gcc,
111 you still want to have cygwin to run make in.
113 If you want to run a cygwin-based gcc, it gets much more
114 complicated. We still want gcc to produce code that does not use
115 cygwin, but the msvcrt runtime. Read the below instruction carefully
116 and understand them. If you don't understand or can't follow the
117 instructions, you probably shouldn't want to build GLib (or GTk+ or
118 GIMP) yourself anyway.
120 0) Get and install Cygwin B20.1.
122 Move the include files and libraries included in Cygwin out of the
123 way not to mix things up... (For example, rename
124 /cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/lib to
125 lib-no-thanks and rename
126 /cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/include to
129 1) Get gcc 2.95.2 built for Cygwin B20.1 from
130 ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/gcc-2.95.2/gcc-2.95.2-cygb20.tar.gz
132 Install it somewhere, let's say G:\gcc-2.95.2 (//g/gcc-2.95.2 when
133 in Cygwin). Add //g/gcc-2.95.2/H-i586-cygwin32/bin to your
134 PATH. I assume you use bash below.
136 Replace the specs file in
137 //g/gcc-2.95.2/H-i586-cygwin32/lib/gcc-lib/i586-cygwin32/2.95.2/specs
138 with the following. (The changes are: Define __MSVCRT__, replace
139 the "1" versions of the crt files with the "2" ones, replace crtdll
140 with msvcrt. Also, extra whitespace squished. )
142 ================ cut here ================
150 -remap %(cpp_cpu) %{posix:-D_POSIX_SOURCE} %{!mno-cygwin:-D__CYGWIN32__ -D__CYGWIN__} %{mno-cygwin:-iwithprefixbefore ../../../../%(mingw_include_path)/include/mingw32 -D__MSVCRT__ -D__MINGW32__=0.2}
162 %{mwindows:--subsystem windows} %{mconsole:--subsystem console} %{mdll:--dll -e _DllMainCRTStartup@12}
165 %{pg:-lgmon} %{!mno-cygwin:-lcygwin} %{mno-cygwin:-lmingw32 -lmoldname -lmsvcrt} %{mwindows:-lgdi32 -lcomdlg32} -luser32 -lkernel32 -ladvapi32 -lshell32
171 %{mdll: %{mno-cygwin:dllcrt2%O%s}} %{!mdll: %{!mno-cygwin:crt0%O%s} %{mno-cygwin:crt2%O%s} %{pg: %{!mno-cygwin:gcrt0%O%s} %{mno-cygwin:gcrt2%O%s}}}
173 *switches_need_spaces:
177 %{funsigned-char:-D__CHAR_UNSIGNED__}
180 -Di386 -D_WIN32 -DWINNT -D_X86_=1 -D__STDC__=1 -D__stdcall=__attribute__((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x)) -Asystem(winnt) -Acpu(i386) -Amachine(i386)
189 . !mno-cygwin;mingw32 mno-cygwin;;
198 mno-cygwin mno-cygwin;
204 %{!ansi:-Di486} -D__i486 -D__i486__
207 %{!ansi:-Di586 -Dpentium} -D__i586 -D__i586__ -D__pentium -D__pentium__
210 %{!ansi:-Di586 -Dk6} -D__i586 -D__i586__ -D__k6 -D__k6__
213 %{!ansi:-Di686 -Dpentiumpro} -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__
219 -Acpu(i386) -Amachine(i386) %{!ansi:-Di386} -D__i386 -D__i386__ %{mcpu=i486:%(cpp_486)} %{m486:%(cpp_486)} %{mpentium:%(cpp_586)} %{mcpu=pentium:%(cpp_586)} %{mpentiumpro:%(cpp_686)} %{mcpu=pentiumpro:%(cpp_686)} %{mcpu=k6:%(cpp_k6)} %{!mcpu*:%{!m486:%{!mpentium*:%(cpp_cpu_default)}}}
222 %{!mcpu*: %{m386:-mcpu=i386 -march=i386} %{m486:-mcpu=i486 -march=i486} %{mpentium:-mcpu=pentium} %{mpentiumpro:-mcpu=pentiumpro}}
228 %{!fsyntax-only: %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t} %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}} %{static:} %{L*} %D %o %{!nostdlib:%{!nodefaultlibs:%G %L %G}} %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*}
231 ================ cut here ================
233 2) Get the Mingw32 runtime sources from
234 ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/gcc-2.95.2/runtime-source-19991107.zip
236 Unpack it somewhere, say //g/src/mingw-runtime-19991107 .
238 Apply the following patches:
240 This makes the mingwm10.dll depend on the stuff that is needed
243 ================ cut here ================
244 diff -ru2 ./mingw/Makefile.in ../../src/mingw-runtime-19991107/mingw/Makefile.in
245 --- ./mingw/Makefile.in Sun Nov 07 12:19:22 1999
246 +++ ../../src/mingw-runtime-19991107/mingw/Makefile.in Mon Nov 08 14:55:38 1999
248 --base-file mingwthrd.base --output-exp mingwthrd.exp
250 -$(THREAD_DLL_NAME) mingwthrd.def: $(DLL_OFILES) Makefile
251 +$(THREAD_DLL_NAME) mingwthrd.def: $(DLL_OFILES) Makefile libmingw32.a libmoldname.a lib$(RUNTIME).a dllcrt$(CRT_ID).o
252 $(DLLTOOL) --as $(AS) --output-def mingwthrd.def $(DLL_OFILES)
253 $(CC) -Wl,--base-file=mingwthrd.base $(DLL_CC_STUFF)
254 ================ cut here ================
256 This enables building the profiling gcrt2.o. I don't know how useful
257 it is, though, there doesn't seem to be any gprof command in cygwin.
259 ================ cut here ================
260 diff -ru2 ./mingw/profile/Makefile.in ../../src/mingw-runtime-19991107/mingw/profile/Makefile.in
261 --- ./mingw/profile/Makefile.in Sun Nov 07 12:18:56 1999
262 +++ ../../src/mingw-runtime-19991107/mingw/profile/Makefile.in Mon Nov 08 12:12:12 1999
266 - $(CC) -U__MSVCRT__ -c -o $@ $(CPPFLAGS) $(CFLAGS) $?
267 + $(CC) -U__MSVCRT__ -c -o $@ $(CPPFLAGS) $(ALL_CFLAGS) $?
270 - $(CC) -D__MSVCRT__ -c -o $@ $(CPPFLAGS) $(CFLAGS) $?
271 + $(CC) -D__MSVCRT__ -c -o $@ $(CPPFLAGS) $(ALL_CFLAGS) $?
273 Makefile: Makefile.in config.status configure
274 ================ cut here ================
276 This fixes a typo in wingdi.h:
278 ================ cut here ================
279 diff -ru2 ./w32api/include/wingdi.h ../../src/mingw-runtime-19991107/w32api/include/wingdi.h
280 --- ./w32api/include/wingdi.h Thu Nov 04 03:42:40 1999
281 +++ ../../src/mingw-runtime-19991107/w32api/include/wingdi.h Mon Nov 08 12:48:02 1999
284 #define FW_EXTRABOLD 800
285 -#define FW_ULTRABOLD FW_EXTRABOOLD
286 +#define FW_ULTRABOLD FW_EXTRABOLD
288 #define FW_BLACK FW_HEAVY
290 ================ cut here ================
292 fpos_t should be long long with MSVCRT.DLL:
294 ================ cut here ================
295 --- stdio.h~ Thu Aug 19 02:47:42 1999
296 +++ stdio.h Mon Jan 17 21:58:20 2000
298 * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL).
299 * Perhaps an unsigned long? TODO?
300 + * In MSVCRT.DLL it's a long long, however.
303 +typedef long long fpos_t;
308 int fgetpos (FILE* fileGetPosition, fpos_t* pfpos);
309 ================ cut here ================
312 (I haven't checked yet if other small errors I have noticed in
313 previous w32api header versions have been corrected.)
315 3) Now you should build the mingw32 and w32api runtime and import libraries.
317 Go to //g/src/mingw-runtime-19991107/w32api. Enter:
319 CC='gcc -mno-cygwin' ./configure i586-pc-mingw32msvc
322 That should complete in a while. It should produce a lot of .a
323 libraries (both import libraries, and a couple of archive
324 libraries), and some .o files. I don't trust make install to do
325 what I want (especially as I didn't give any --prefix argument to
326 the configure...), so I install the stuff manually:
329 mkdir //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
330 cp *.a //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
331 cp crt2.o crtdll2.o //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
333 mkdir //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
334 cp *.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
336 Now go to ../../mingw, and run the same configure command, and do a
339 CC='gcc -mno-cygwin' ./configure i586-pc-mingw32msvc
342 Then install the mingw32 libraries and headers:
343 cp *.a //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
344 mkdir //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32/sys
345 cp include/sys/*.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32/sys
346 cp include/*.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
349 4) Get an updated set of binutils for cygwin B20.1 from
350 ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/gcc-2.95.2/binutils-2.9.4-cygb20.tar.gz
351 Unpack that in your /cygnus/cygwin-b20 directory. The relevant
352 difference is: dlltool now parses GCC generated export directives
353 correctly for DATA items.
355 5) Whew. That hopefully should be it.
357 Next, go back to the GLib directory and build using `make -f
358 makefile.cygwin`. Building the dlls uses the script build-dll which
359 is somewhat of a hack. But I couldn't get things working in a cleaner
362 --Tor Lillqvist <tml@iki.fi>