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.
60 Before building you must get the pthreads library for Win32 from
61 http://sourceware.cygnus.com/pthreads-win32/. The pthreads-win32
62 snapshot from 1999-05-30 is the one that should be used. Edit the
63 location of the pthreads library and include files in makefile.msc or
64 makefile.cygwin. The pthreads distribution includes the precompiled dll
65 and import libraries both for MSVC and gcc.
67 The pthreads for Win32 package that the thread support uses supposedly
68 isn't quite ready yet, and thus threads stuff should not be relied
69 upon for anything serious.
71 Where are the makefiles?
72 ========================
74 If you are building from a CVS snapshot, you will not have any
75 makefile.msc or makefile.cygwin file. You should copy the
76 corresponding makefile.msc.in or makefile.cygwin.in file to that name,
77 and edit the line that sets GLIB_VER to the correct version number.
79 This is done automatically when an official distribution package is
85 If using the Microsoft toolchain, build with `nmake -f
86 makefile.msc`. Install with `nmake -f makefile.msc install`.
91 I use the latest and greatest gcc, gcc-2.95.2. 2.95 will also work.
92 Earlier version might, but you are on your own.
94 Read and understand these instruction carefully. If you don't
95 understand or can't follow the instructions, you probably shouldn't
96 want to build GLib (or GTk+ or GIMP) yourself anyway. Unfortunately,
97 even building software that just *use* GLib or GTk+ also require to
98 have the right compiler set up the right way, so follow these
99 instructions in that case, too.
101 0) Get and install Cygwin B20.1.
103 Move the include files and libraries included in Cygwin out of the
104 way not to mix things up... (For example, rename
105 /cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/lib to
106 lib-no-thanks and rename
107 /cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/include to
110 1) Get gcc 2.95.2 built for Cygwin B20.1 from
111 ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/gcc-2.95.2/gcc-2.95.2-cygb20.tar.gz
113 Install it somewhere, let's say G:\gcc-2.95.2 (//g/gcc-2.95.2 when
114 in Cygwin). Add //g/gcc-2.95.2/H-i586-cygwin32/bin to your
115 PATH. I assume you use bash below.
117 Replace the specs file in
118 //g/gcc-2.95.2/H-i586-cygwin32/lib/gcc-lib/i586-cygwin32/2.95.2/specs
119 with the following. (The changes are: Define __MSVCRT__, replace
120 the "1" versions of the crt files with the "2" ones, replace crtdll
121 with msvcrt. Also, extra whitespace squished. )
123 ================ cut here ================
131 -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}
143 %{mwindows:--subsystem windows} %{mconsole:--subsystem console} %{mdll:--dll -e _DllMainCRTStartup@12}
146 %{pg:-lgmon} %{!mno-cygwin:-lcygwin} %{mno-cygwin:-lmingw32 -lmoldname -lmsvcrt} %{mwindows:-lgdi32 -lcomdlg32} -luser32 -lkernel32 -ladvapi32 -lshell32
152 %{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}}}
154 *switches_need_spaces:
158 %{funsigned-char:-D__CHAR_UNSIGNED__}
161 -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)
170 . !mno-cygwin;mingw32 mno-cygwin;;
179 mno-cygwin mno-cygwin;
185 %{!ansi:-Di486} -D__i486 -D__i486__
188 %{!ansi:-Di586 -Dpentium} -D__i586 -D__i586__ -D__pentium -D__pentium__
191 %{!ansi:-Di586 -Dk6} -D__i586 -D__i586__ -D__k6 -D__k6__
194 %{!ansi:-Di686 -Dpentiumpro} -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__
200 -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)}}}
203 %{!mcpu*: %{m386:-mcpu=i386 -march=i386} %{m486:-mcpu=i486 -march=i486} %{mpentium:-mcpu=pentium} %{mpentiumpro:-mcpu=pentiumpro}}
209 %{!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*}
212 ================ cut here ================
214 2) Get the Mingw32 runtime sources from
215 ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/gcc-2.95.2/runtime-source-19991107.zip
217 Unpack it somewhere, say //g/src/mingw-runtime-19991107 .
219 Apply the following patches:
221 This makes the mingwm10.dll depend on the stuff that is needed
224 ================ cut here ================
225 diff -ru2 ./mingw/Makefile.in ../../src/mingw-runtime-19991107/mingw/Makefile.in
226 --- ./mingw/Makefile.in Sun Nov 07 12:19:22 1999
227 +++ ../../src/mingw-runtime-19991107/mingw/Makefile.in Mon Nov 08 14:55:38 1999
229 --base-file mingwthrd.base --output-exp mingwthrd.exp
231 -$(THREAD_DLL_NAME) mingwthrd.def: $(DLL_OFILES) Makefile
232 +$(THREAD_DLL_NAME) mingwthrd.def: $(DLL_OFILES) Makefile libmingw32.a libmoldname.a lib$(RUNTIME).a dllcrt$(CRT_ID).o
233 $(DLLTOOL) --as $(AS) --output-def mingwthrd.def $(DLL_OFILES)
234 $(CC) -Wl,--base-file=mingwthrd.base $(DLL_CC_STUFF)
235 ================ cut here ================
237 This enables building the profiling gcrt2.o. I don't know how useful
238 it is, though, there doesn't seem to be any gprof command in cygwin.
240 ================ cut here ================
241 diff -ru2 ./mingw/profile/Makefile.in ../../src/mingw-runtime-19991107/mingw/profile/Makefile.in
242 --- ./mingw/profile/Makefile.in Sun Nov 07 12:18:56 1999
243 +++ ../../src/mingw-runtime-19991107/mingw/profile/Makefile.in Mon Nov 08 12:12:12 1999
247 - $(CC) -U__MSVCRT__ -c -o $@ $(CPPFLAGS) $(CFLAGS) $?
248 + $(CC) -U__MSVCRT__ -c -o $@ $(CPPFLAGS) $(ALL_CFLAGS) $?
251 - $(CC) -D__MSVCRT__ -c -o $@ $(CPPFLAGS) $(CFLAGS) $?
252 + $(CC) -D__MSVCRT__ -c -o $@ $(CPPFLAGS) $(ALL_CFLAGS) $?
254 Makefile: Makefile.in config.status configure
255 ================ cut here ================
257 This fixes a typo in wingdi.h:
259 ================ cut here ================
260 diff -ru2 ./w32api/include/wingdi.h ../../src/mingw-runtime-19991107/w32api/include/wingdi.h
261 --- ./w32api/include/wingdi.h Thu Nov 04 03:42:40 1999
262 +++ ../../src/mingw-runtime-19991107/w32api/include/wingdi.h Mon Nov 08 12:48:02 1999
265 #define FW_EXTRABOLD 800
266 -#define FW_ULTRABOLD FW_EXTRABOOLD
267 +#define FW_ULTRABOLD FW_EXTRABOLD
269 #define FW_BLACK FW_HEAVY
271 ================ cut here ================
273 (I haven't checked yet if other small errors I have noticed in
274 previous w32api header versions have been corrected.)
276 3) Now you should build the mingw32 and w32api runtime and import libraries.
278 Go to //g/src/mingw-runtime-19991107/w32api. Enter:
280 CC='gcc -mno-cygwin' ./configure i586-pc-mingw32msvc
283 That should complete in a while. It should produce a lot of .a
284 libraries (both import libraries, and a couple of archive
285 libraries), and some .o files. I don't trust make install to do
286 what I want (especially as I didn't give any --prefix argument to
287 the configure...), so I install the stuff manually:
290 mkdir //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
291 cp *.a //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
293 mkdir //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
294 cp *.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
296 Now go to ../../mingw, and run the same configure command, and do a
299 CC='gcc -mno-cygwin' ./configure i586-pc-mingw32msvc
302 Then install the mingw32 libraries and headers:
303 cp *.a //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
304 mkdir //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32/sys
305 cp include/sys/*.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32/sys
306 cp include/*.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
309 4) Get an updated set of binutils for cygwin B20.1 from
310 ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/gcc-2.95.2/binutils-2.9.4-cygb20.tar.gz
311 Unpack that in your /cygnus/cygwin-b20 directory. The relevant
312 difference is: dlltool now parses GCC generated export directives
313 correctly for DATA items.
315 5) Whew. That hopefully should be it.
317 Next, go back to the GLib directory and build using `make -f
318 makefile.cygwin`. Building the dlls uses the script build-dll which
319 is somewhat of a hack. But I couldn't get things working in a cleaner
322 --Tor Lillqvist <tml@iki.fi>