b56f0e967f23554064ade7d21e3dc45838fc580a
[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 binaries (DLLs), surf to
6 http://www.gimp.org/win32/ . "Native" means that we use the Win32 API
7 only, and no POSIX (Unix) emulation layer except that provided by the
8 Microsoft runtime C library.
9
10 To build GLib on Win32, you can use either gcc or the Microsoft
11 compiler and tools. Both the compiler from MSVC 5.0 and from MSVC 6.0
12 have been used successfully.
13
14 But note that to just *use* GLib on Windows, there is no need to build
15 it, prebuilt DLLs are available from the webiste above.
16
17 The following preprocessor macros are used for conditional compilation
18 related to Win32:
19
20 - G_OS_WIN32 is defined when compiling for Win32, *and* without
21   any POSIX emulation, other that to the extent provided by the
22   bundled Microsoft C library (msvcrt.dll) and the pthreads-win32
23   library. For instance, pathnames are in the native Windows syntax.
24
25 - G_WITH_CYGWIN is defined if compiling for the Cygwin
26   environment. Note that G_OS_WIN32 is *not* defined in that case, as
27   Cygwin is supposed to behave like Unix. G_OS_UNIX *is* defined when
28   compiling for Cygwin.
29
30 - G_PLATFORM_WIN32 is defined when either G_OS_WIN32 or G_WITH_CYGWIN
31   is defined.
32
33 The Win32 port of GLib and related software uses only G_OS_WIN32. As
34 G_OS_WIN32 is defined in glibconfig.h, it is available to all source
35 files that use GLib (or GTk+, which uses GLib).
36
37 Additionally, there are the compiler-specific macros:
38 - __GNUC__ is defined when using GCC
39 - _MSC_VER is defined when using the Microsoft compiler
40
41 G_OS_WIN32 implies using the Microsoft C runtime MSVCRT.DLL. GLib is
42 not known to work with the older CRTDLL.DLL runtime, or the static
43 Microsoft C runtime libraries.
44
45 Building software that use GLib or GTk+
46 =======================================
47
48 Even building software that just *use* GLib or GTk+ also require to
49 have the right compiler set up the right way, so if you intend to use
50 gcc, follow the relevant instructions below in that case, too.
51
52 Libiconv
53 ========
54
55 Before building GLib you must also have the libiconv library, either
56 from the same website mentioned above, or from it's homepage at
57 http://clisp.cons.org/~haible/packages-libiconv.html. Libiconv has
58 makefiles for building with MS Visual C only, but as it is one source
59 file only, building it "by hand" with gcc isn't hard.
60
61 Where are the makefiles?
62 ========================
63
64 If you are building from a CVS snapshot, you will not have any
65 makefile.mingw or makefile.msc file. You should copy the corresponding
66 makefile.mingw.in or makefile.msc.in file to that name, and edit the
67 @GLIB_VERSION@ strings to the correct version number.
68
69 This is done automatically when an official GLib source distribution
70 package is built.
71
72 Building GLib with gcc
73 ======================
74
75 I use the latest gcc, gcc-2.95.3. Version 2.95.2 will most probably
76 also work.
77
78 You can either use gcc running on Cygwin, or the "pure" mingw
79 gcc. Using the latter is much easier. 
80
81 Just fetch the latest version of gcc for mingw and the msvcrt runtime,
82 from www.mingw.org.
83
84 Set up your PATH so that the gcc from the bin directory that got
85 created above is the one that gets used. Even if you run the mingw
86 gcc, you still want to have Cygwin to run make in.
87
88 Then run make -f makefile.mingw. 
89
90 I use the -fnative-struct flag, which means that in order to use the
91 prebuilt DLLs (especially of GTK+), you *must* also use that flag.
92 (This flag means that the struct layout is identical to that used by
93 MSVC. This is essential if the same DLLs are to be usable both from
94 gcc- and MSVC-compiled code, which definitely is a good thing.)
95
96 It is also possible to use the auto*, ./configure and libtool
97 mechanism when building for mingw. You should be running Cygwin, or
98 maybe cross-compiling from real Unix, for the configure script to
99 work, obviously. The same libtool issue has to be taken into account
100 as when building for Cygwin: You most probably should have a very new
101 libtool. Remember to invoke configure with CC='gcc -fnative-struct' if
102 you want to produce DLLs binary compatible with the "official" ones.
103
104 But please note that the ./configure mechanism should not blindly be
105 used to build a GLib to be distributed to potential developers because
106 it produces a compiler-dependent glibconfig.h (and config.h, but that
107 shouldn't matter). For instance, the typedef for gint64 is long long
108 with gcc, but __int64 with MSVC. Otherwise, there really shouldn't be
109 any reason to distribute separate GLib DLLs for gcc and MSVC users, as
110 both compiler+tools generate code that uses the same C runtime
111 library. Thus one either has to edit glibconfig.h afterwards, or use
112 the hand-written config.h.win32 and glibconfig.h.win32.
113
114 There are probably also other hickups when using auto* and configure
115 to build for mingw, sigh. Every now and then I try to get rid of the
116 hand-written makefiles and configuration headers for Win32, and start
117 fooling around with auto* etc, but after a while give up and fall
118 back.
119
120 If you want to run the Cygwin-based gcc, it gets a bit more
121 complicated. We still want gcc to produce code that does not use
122 Cygwin, but the msvcrt runtime. In theory it should work to use the
123 -no-cygwin flag, but I haven't tested that lately.
124
125 If you would want to use the Cygwin tools to generate a GLib that
126 *does* use the Cygwin runtime, the normal Unix configuration method
127 should work as if on Unix. Note that successfully producing shared
128 libraries (DLLs) most probably requires you to have a very new
129 libtool. (And a new libtool probably requires rather new autoconf and
130 automake.)
131
132 Building with MSVC
133 ==================
134
135 If using the Microsoft toolchain, build with `nmake -f
136 makefile.msc`.
137
138 --Tor Lillqvist <tml@iki.fi>