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, running under cygwin-b20.1. To successfully
15 use gcc, follow the instructions below. We want to use gcc
16 -mno-cygwin, i.e. produce executables (.exe and .dll files) that do
17 *not* require the cygwin runtime library. This is sometimes called
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 Read these instruction carefully and understand them. If you don't
103 understand or can't follow the instructions, you probably shouldn't
104 want to build GLib (or GTk+ or GIMP) yourself anyway.
106 0) Get and install Cygwin B20.1.
108 Move the include files and libraries included in Cygwin out of the
109 way not to mix things up... (For example, rename
110 /cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/lib to
111 lib-no-thanks and rename
112 /cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/include to
115 1) Get gcc 2.95.2 built for Cygwin B20.1 from
116 ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/gcc-2.95.2/gcc-2.95.2-cygb20.tar.gz
118 Install it somewhere, let's say G:\gcc-2.95.2 (//g/gcc-2.95.2 when
119 in Cygwin). Add //g/gcc-2.95.2/H-i586-cygwin32/bin to your
120 PATH. I assume you use bash below.
122 Replace the specs file in
123 //g/gcc-2.95.2/H-i586-cygwin32/lib/gcc-lib/i586-cygwin32/2.95.2/specs
124 with the following. (The changes are: Define __MSVCRT__, replace
125 the "1" versions of the crt files with the "2" ones, replace crtdll
126 with msvcrt. Also, extra whitespace squished. )
128 ================ cut here ================
136 -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}
148 %{mwindows:--subsystem windows} %{mconsole:--subsystem console} %{mdll:--dll -e _DllMainCRTStartup@12}
151 %{pg:-lgmon} %{!mno-cygwin:-lcygwin} %{mno-cygwin:-lmingw32 -lmoldname -lmsvcrt} %{mwindows:-lgdi32 -lcomdlg32} -luser32 -lkernel32 -ladvapi32 -lshell32
157 %{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}}}
159 *switches_need_spaces:
163 %{funsigned-char:-D__CHAR_UNSIGNED__}
166 -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)
175 . !mno-cygwin;mingw32 mno-cygwin;;
184 mno-cygwin mno-cygwin;
190 %{!ansi:-Di486} -D__i486 -D__i486__
193 %{!ansi:-Di586 -Dpentium} -D__i586 -D__i586__ -D__pentium -D__pentium__
196 %{!ansi:-Di586 -Dk6} -D__i586 -D__i586__ -D__k6 -D__k6__
199 %{!ansi:-Di686 -Dpentiumpro} -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__
205 -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)}}}
208 %{!mcpu*: %{m386:-mcpu=i386 -march=i386} %{m486:-mcpu=i486 -march=i486} %{mpentium:-mcpu=pentium} %{mpentiumpro:-mcpu=pentiumpro}}
214 %{!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*}
217 ================ cut here ================
219 2) Get the Mingw32 runtime sources from
220 ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/gcc-2.95.2/runtime-source-19991107.zip
222 Unpack it somewhere, say //g/src/mingw-runtime-19991107 .
224 Apply the following patches:
226 This makes the mingwm10.dll depend on the stuff that is needed
229 ================ cut here ================
230 diff -ru2 ./mingw/Makefile.in ../../src/mingw-runtime-19991107/mingw/Makefile.in
231 --- ./mingw/Makefile.in Sun Nov 07 12:19:22 1999
232 +++ ../../src/mingw-runtime-19991107/mingw/Makefile.in Mon Nov 08 14:55:38 1999
234 --base-file mingwthrd.base --output-exp mingwthrd.exp
236 -$(THREAD_DLL_NAME) mingwthrd.def: $(DLL_OFILES) Makefile
237 +$(THREAD_DLL_NAME) mingwthrd.def: $(DLL_OFILES) Makefile libmingw32.a libmoldname.a lib$(RUNTIME).a dllcrt$(CRT_ID).o
238 $(DLLTOOL) --as $(AS) --output-def mingwthrd.def $(DLL_OFILES)
239 $(CC) -Wl,--base-file=mingwthrd.base $(DLL_CC_STUFF)
240 ================ cut here ================
242 This enables building the profiling gcrt2.o. I don't know how useful
243 it is, though, there doesn't seem to be any gprof command in cygwin.
245 ================ cut here ================
246 diff -ru2 ./mingw/profile/Makefile.in ../../src/mingw-runtime-19991107/mingw/profile/Makefile.in
247 --- ./mingw/profile/Makefile.in Sun Nov 07 12:18:56 1999
248 +++ ../../src/mingw-runtime-19991107/mingw/profile/Makefile.in Mon Nov 08 12:12:12 1999
252 - $(CC) -U__MSVCRT__ -c -o $@ $(CPPFLAGS) $(CFLAGS) $?
253 + $(CC) -U__MSVCRT__ -c -o $@ $(CPPFLAGS) $(ALL_CFLAGS) $?
256 - $(CC) -D__MSVCRT__ -c -o $@ $(CPPFLAGS) $(CFLAGS) $?
257 + $(CC) -D__MSVCRT__ -c -o $@ $(CPPFLAGS) $(ALL_CFLAGS) $?
259 Makefile: Makefile.in config.status configure
260 ================ cut here ================
262 This fixes a typo in wingdi.h:
264 ================ cut here ================
265 diff -ru2 ./w32api/include/wingdi.h ../../src/mingw-runtime-19991107/w32api/include/wingdi.h
266 --- ./w32api/include/wingdi.h Thu Nov 04 03:42:40 1999
267 +++ ../../src/mingw-runtime-19991107/w32api/include/wingdi.h Mon Nov 08 12:48:02 1999
270 #define FW_EXTRABOLD 800
271 -#define FW_ULTRABOLD FW_EXTRABOOLD
272 +#define FW_ULTRABOLD FW_EXTRABOLD
274 #define FW_BLACK FW_HEAVY
276 ================ cut here ================
278 fpos_t should be long long with MSVCRT.DLL:
280 ================ cut here ================
281 --- stdio.h~ Thu Aug 19 02:47:42 1999
282 +++ stdio.h Mon Jan 17 21:58:20 2000
284 * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL).
285 * Perhaps an unsigned long? TODO?
286 + * In MSVCRT.DLL it's a long long, however.
289 +typedef long long fpos_t;
294 int fgetpos (FILE* fileGetPosition, fpos_t* pfpos);
295 ================ cut here ================
298 (I haven't checked yet if other small errors I have noticed in
299 previous w32api header versions have been corrected.)
301 3) Now you should build the mingw32 and w32api runtime and import libraries.
303 Go to //g/src/mingw-runtime-19991107/w32api. Enter:
305 CC='gcc -mno-cygwin' ./configure i586-pc-mingw32msvc
308 That should complete in a while. It should produce a lot of .a
309 libraries (both import libraries, and a couple of archive
310 libraries), and some .o files. I don't trust make install to do
311 what I want (especially as I didn't give any --prefix argument to
312 the configure...), so I install the stuff manually:
315 mkdir //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
316 cp *.a //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
317 cp crt2.o crtdll2.o //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
319 mkdir //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
320 cp *.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
322 Now go to ../../mingw, and run the same configure command, and do a
325 CC='gcc -mno-cygwin' ./configure i586-pc-mingw32msvc
328 Then install the mingw32 libraries and headers:
329 cp *.a //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
330 mkdir //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32/sys
331 cp include/sys/*.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32/sys
332 cp include/*.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
335 4) Get an updated set of binutils for cygwin B20.1 from
336 ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/gcc-2.95.2/binutils-2.9.4-cygb20.tar.gz
337 Unpack that in your /cygnus/cygwin-b20 directory. The relevant
338 difference is: dlltool now parses GCC generated export directives
339 correctly for DATA items.
341 5) Whew. That hopefully should be it.
343 Next, go back to the GLib directory and build using `make -f
344 makefile.cygwin`. Building the dlls uses the script build-dll which
345 is somewhat of a hack. But I couldn't get things working in a cleaner
348 --Tor Lillqvist <tml@iki.fi>