ad4b683d926c5e31c789bdaec19f32faf12df6fd
[platform/upstream/glib.git] / README.win32
1 General
2 =======
3
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
9 library is used.
10
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 egcs-1.1.2 (as distributed by
14 Mumit Khan), running under cygwin-b20.1. To successfully use gcc,
15 follow the instructions below. We want to use gcc -mno-cygwin,
16 i.e. produce executables (.exe and .dll files) that do *not* require
17 the cygwin runtime library. This is sometimes called "mingw32".
18
19 To test the GLib functions, go to the tests subdirectory and enter
20 `nmake -f makefile.msc check` or `make -f makefile.cygwin check`.
21
22 If you would want to use the cygwin tools to generate executables that
23 *do* use the cygwin runtime, the normal Unix configuration method
24 should work as if on Unix. But it won't produce DLLs. At least I
25 haven't succeeded in that.
26
27 With a little work, it might be possible to use the ./configure
28 mechanism also with a "mingw32" configuration.
29
30 The following preprocessor macros are defined in glibconfig.h and used
31 for conditional compilation related to Win32:
32
33 - WIN32 is defined when compiling for the Win32 platform, regardless
34   if using the X11 or Win32 windowing API (in the case of GLib, this
35   dimension isn't significant), regardless whether using a more or
36   less complete POSIX emulation runtime layer (like Cygwin) or not.
37
38 - NATIVE_WIN32 is defined when compiling for Win32, *and* without
39   any POSIX emulation, other that to the extent provided by the
40   bundled Microsoft C library (msvcrt.dll) and the pthreads-win32
41   library. For instance, pathnames are in the native Windows syntax.
42
43 The Win32 port uses the combination with both of those on. As these
44 are in glibconfig.h, they are available to all source files that use
45 GLib (or GTk+, which uses GLib).
46
47 Additionally, there are the compiler-specific macros:
48 - _MSC_VER is defined when using the Microsoft compiler
49 - __GNUC__ is defined when using GCC (i.e. egcs)
50
51 Some of the usage of these macros used to be a bit mixed up, and had
52 to be straightened out when adding the gcc support. In particular, I
53 used to check for _MSC_VER in some places where I really wanted to
54 check for the Microsoft C library, and those checks has now been
55 changed to NATIVE_WIN32. NATIVE_WIN32 ought to be renamed to
56 USE_MSVCRT.
57
58 Pthreads library
59 ================
60
61 Before building you must get the pthreads library for Win32 from
62 http://sourceware.cygnus.com/pthreads-win32/. The pthreads-win32
63 snapshot from 1999-05-30 is the one that should be used. Edit the
64 location of the pthreads library and include files in makefile.msc or
65 makefile.cygwin. The pthreads distribution includes the precompiled dll
66 and import libraries both for MSVC and gcc.
67
68 The pthreads for Win32 package that the thread support uses supposedly
69 isn't quite ready yet, and thus threads stuff should not be relied
70 upon for anything serious.
71
72 Where are the makefiles?
73 ========================
74
75 If you are building from a CVS snapshot, you will not have any
76 makefile.msc or makefile.cygwin file. You should copy the
77 corresponding makefile.msc.in or makefile.cygwin.in file to that name,
78 and edit the line that sets GLIB_VER to the correct version number.
79
80 This is done automatically when an official distribution package is
81 built.
82
83 Building with MSVC
84 ==================
85
86 If using the Microsoft toolchain, build with `nmake -f
87 makefile.msc`. Install with `nmake -f makefile.msc install`. 
88
89 Building with gcc
90 =================
91
92 The gcc support was added quite recently, but seems to work. Debugging
93 with gdb works. I prefer to use the msvcrt runtime and not the default
94 crtdll. Especially, as the pthread library also uses msvcrt, using
95 crtdll would probably not be a good idea at all. Using msvcrt can be
96 achieved by applying the following diff to the specs file, which
97 typically is installed as
98 C:\cygnus\cygwin-b20\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\egcs-2.91.66\specs.
99
100 Sorry for the illegibility of this diff, but the specs file is like
101 that... This patch replaces -lcrtdll with -lmsvcrt, replaces crt1 with
102 crt2, removes -lmoldname (because using functions from it would pull
103 in crtdll.dll), and defines __MSVCRT__.
104
105 --- specs.ORIG  Sun Apr 25 00:40:40 1999
106 +++ specs       Sun Apr 25 00:48:04 1999
107 @@ -23 +23 @@
108 -%{pg:-lgmon}                   %{!mno-cygwin:-lcygwin}                   %{mno-cygwin:-lmingw32 -lmoldname -lcrtdll}                   %{mwindows:-luser32 -lgdi32 -lcomdlg32}                   -lkernel32 -ladvapi32 -lshell32
109 +%{pg:-lgmon}                   %{!mno-cygwin:-lcygwin}                   %{mno-cygwin:-lmingw32 -lmsvcrt}                   %{mwindows:-luser32 -lgdi32 -lcomdlg32}              -lkernel32 -ladvapi32 -lshell32
110 @@ -29 +29 @@
111 -%{mdll: %{!mno-cygwin:dllcrt0%O%s}                                 %{mno-cygwin:dllcrt1%O%s}}                         %{!mdll: %{!mno-cygwin:crt0%O%s}                                  %{mno-cygwin:crt1%O%s} %{pg:gcrt0%O%s}}
112 +%{mdll: %{!mno-cygwin:dllcrt0%O%s}                                 %{mno-cygwin:dllcrt2%O%s}}                         %{!mdll: %{!mno-cygwin:crt0%O%s}                                  %{mno-cygwin:crt2%O%s} %{pg:gcrt0%O%s}}
113 @@ -38 +38 @@
114 --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)
115 +-Di386 -D_WIN32 %{mno-cygwin:-D__MSVCRT__ } -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) 
116
117 You should also fix two bugs in the mingw32 headers: The type of
118 _dev_t in the header mingw32/sys/types.h should be unsigned int, not
119 short. The type for st_uid in sys/stat.h to be short, not int. This is
120 what the Microsoft's headers and runtime library use. Otherwise
121 accessing the fields in a stat struct as filled in by the stat and
122 fstat functions in the MS library will cause various interesting
123 failures.
124
125 You also will have to get the mingw32 runtime source from
126 ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/runtime/source-1999-04-05.tar.gz
127 (this is the source to the "mingw32" part of Mumit Khan's egcs-1.1.2
128 distribution.) Unpack it and fix the prototype and call to
129 __getmainargs() in init.c to include one more parameter, an int *,
130 which should be passed the address of a zero int. Code snippets below:
131
132 ...
133 #ifdef __MSVCRT__
134 extern void __getmainargs(int *, char***, char***, int, int *);
135 #else
136 ...
137 #ifdef __MSVCRT__
138         int newmode = 0;
139         (void) __getmainargs(&_argc, &_argv, &dummy_environ, _CRT_glob, &newmode);
140 #else
141 ...
142
143 Remake dllcrt2.o (which is the file which gets linked into dlls when
144 using msvcrt, as per the specs file above), and move it into place
145 (typically C:\cygnus\cygwin-b20\H-i586-cygwin32\i586-cygwin32\lib\dllcrt2.o).
146
147 Next, go back to the GLib directory and build using `make -f makefile.cygwin`.
148 Building the dlls uses the script build-dll which is an awful hack. But
149 I couldn't get things working in a cleaner way.
150
151 --Tor Lillqvist <tml@iki.fi>