1Tor Lillqvist <tml@iki.fi> 2Hans Breuer <hans@breuer.org> 3 4The general parts, and the section about gcc and autoconfiscated build 5are by Tor Lillqvist. The sections about MSVC build is by Hans Breuer. 6 7General 8======= 9 10For prebuilt binaries (DLLs and EXEs) and developer packages (headers, 11import libraries) of GLib, Pango, GTK+ etc for Windows, go to 12http://www.gtk.org/download-windows.html . They are for "native" 13Windows meaning they use the Win32 API and Microsoft C runtime library 14only. No POSIX (Unix) emulation layer like Cygwin in involved. 15 16To build GLib on Win32, you can use either gcc ("mingw") or the 17Microsoft compiler and tools. For the latter, MSVC6 and later have 18been used successfully. Also the Digital Mars C/C++ compiler have been 19used. 20 21People have also successfully cross-compiled GLib for Win32 from Linux 22using the cross-mingw packages. 23 24Note that to just *use* GLib on Windows, there is no need to build it 25yourself. 26 27On Windows setting up a correct build environment can be quite a task, 28especially if you are used to just type "./configure; make" on Linux, 29and expect things to work as smoothly on Windows. 30 31The following preprocessor macros are to be used for conditional 32compilation related to Win32 in GLib-using code: 33 34- G_OS_WIN32 is defined when compiling for native Win32, without 35 any POSIX emulation, other than to the extent provided by the 36 bundled Microsoft C library (msvcr*.dll). 37 38- G_WITH_CYGWIN is defined if compiling for the Cygwin 39 environment. Note that G_OS_WIN32 is *not* defined in that case, as 40 Cygwin is supposed to behave like Unix. G_OS_UNIX *is* defined by a GLib 41 for Cygwin. 42 43- G_PLATFORM_WIN32 is defined when either G_OS_WIN32 or G_WITH_CYGWIN 44 is defined. 45 46These macros are defined in glibconfig.h, and are thus available in 47all source files that include <glib.h>. 48 49Additionally, there are the compiler-specific macros: 50- __GNUC__ is defined when using gcc 51- _MSC_VER is defined when using the Microsoft compiler 52- __DMC__ is defined when using the Digital Mars C/C++ compiler 53 54G_OS_WIN32 implies using the Microsoft C runtime, normally 55msvcrt.dll. GLib is not known to work with the older crtdll.dll 56runtime, or the static Microsoft C runtime libraries libc.lib and 57libcmt.lib. It apparently does work with the debugging version of 58msvcrt.dll, msvcrtd.dll. If compiled with Microsoft compilers newer 59than MSVC6, it also works with their compiler-specific runtimes, like 60msvcr70.dll or msvcr80.dll. Please note that it's non totally clear if 61you would be allowed by the license to distrubute a GLib linked to 62msvcr70.dll or msvcr80.dll, as those are not part of the operating 63system, but of the MSVC product. msvcrt.dll is part of Windows. 64 65Building software that use GLib or GTK+ 66======================================= 67 68Building software that just *uses* GLib or GTK+ also require to have 69the right compiler set up the right way. If you intend to use gcc, 70follow the relevant instructions below in that case, too. 71 72Tor uses gcc with the -mms-bitfields flag which means that in order to 73use the prebuilt DLLs (especially of GTK+), if you compile your code 74with gcc, you *must* also use that flag. This flag means that the 75struct layout rules are identical to those used by MSVC. This is 76essential if the same DLLs are to be usable both from gcc- and 77MSVC-compiled code. Such compatibility is desirable. 78 79When using the prebuilt GLib DLLs that use msvcrt.dll from code that 80uses other C runtimes like for example msvcr70.dll, one should note 81that one cannot use such GLib API that take or returns file 82descriptors. On Windows, a file descriptor (the small integer as 83returned by open() and handled by related functions, and included in 84the FILE struct) is an index into a table local to the C runtime 85DLL. A file descriptor in one C runtime DLL does not have the same 86meaning in another C runtime DLL. 87 88Building GLib 89============= 90 91Again, first decide whether you really want to do this. 92 93Before building GLib you must also have a GNU gettext-runtime 94developer package. Get prebuilt binaries of gettext-runtime from 95http://www.gtk.org/download-windows.html . 96 97Autoconfiscated build (with gcc) 98================================ 99 100Tor uses gcc 3.4.5 and the rest of the mingw utilities, including MSYS 101from www.mingw.org. Somewhat earlier or later versions of gcc 102presumably also work fine. 103 104Using Cygwin's gcc with the -mno-cygwin switch is not recommended. In 105theory it should work, but Tor hasn't tested that lately. It can 106easily lead to confusing situations where one mixes headers for Cygwin 107from /usr/include with the headers for native software one really 108should use. Ditto for libraries. 109 110If you want to use mingw's gcc, install gcc, win32api, binutils and 111MSYS from www.mingw.org. 112 113Tor invokes configure using: 114 115CC='gcc -mtune=pentium3 -mthreads' CPPFLAGS='-I/opt/gnu/include' \ 116 LDFLAGS='-L/opt/gnu/lib -Wl,--enable-auto-image-base' CFLAGS=-O2 \ 117 ./configure --disable-gtk-doc --prefix=$TARGET 118 119The /opt/gnu mentioned contains the header files for GNU and (import) 120libraries for GNU libintl. The build scripts used to produce the 121prebuilt binaries are included in the "dev" packages. 122 123Please note that the ./configure mechanism should not blindly be used 124to build a GLib to be distributed to other developers because it 125produces a compiler-dependent glibconfig.h. For instance, the typedef 126for gint64 is long long with gcc, but __int64 with MSVC. 127 128Except for this and a few other minor issues, there shouldn't be any 129reason to distribute separate GLib headers and DLLs for gcc and MSVC6 130users, as the compilers generate code that uses the same C runtime 131library. 132 133The DLL generated by either compiler is binary compatible with the 134other one. Thus one either has to manually edit glibconfig.h 135afterwards, or use the supplied glibconfig.h.win32 which has been 136produced by running configure twice, once using gcc and once using 137MSVC, and merging the resulting files with diff -D. 138 139For MSVC7 and later (Visual C++ .NET 2003, Visual C++ 2005, Visual C++ 1402008 etc) it is preferred to use specific builds of GLib DLLs that use 141the same C runtime as the code that uses GLib. Such DLLs should be 142named differently than the ones that use msvcrt.dll. 143 144For GLib, the DLL is called libglib-2.0-0.dll, and the import 145libraries libglib-2.0.dll.a and glib-2.0.lib. Note that the "2.0" is 146part of the "basename" of the library, it is not something that 147libtool has added. The -0 suffix is added by libtool and is the value 148of "LT_CURRENT - LT_AGE". The 0 is *not* part of the version number of 149GLib, although, for GLib 2.x.0, it happens to be the same. The 150LT_CURRENT - LT_AGE value will on purpose be kept as zero as long as 151binary compatibility is maintained. For the gory details, see 152configure.in and libtool documentation. 153 154Cross-compiling 155=============== 156 157It is possible to build GLib using a cross compiler. See 158docs/reference/glib/html/glib-cross-compiling.html (part of the GLib 159reference manual) for more information. 160 161Building with MSVC 162================== 163 164If you are building from a SVN snapshot, you will not have any 165makefile.msc files. You should copy the corresponding makefile.msc.in 166file to that name, and replace any @...@ strings with the correct 167value. 168 169This is done automatically when an official GLib source distribution 170package is built, so if you get GLib from a source distribution 171package, there should be makefile.msc files ready to use (after some 172editing). 173 174The hand-written makefile.msc files, and the stuff in the "build" 175subdirectory, produce DLLs and import libraries that match what the 176so-called autoconfiscated build produces. 177 178All the MSVC makefiles are for the command line build with nmake. If 179you want to use the VC-UI you can simply create wrapper .dsp makefiles 180(read the VC docs how to do so). 181 182Some modules may require Perl to auto-generate files. The goal (at 183least Hans's) is to not require any more tools. 184 185Build with: 186 187nmake -f makefile.msc 188 or 189nmake -f makefile.msc DEBUG=1 190 191[ 192 The former will create 'release' versions of the DLLs. If you 193 plan to distribute you DLLs please use this command. The latter 194 will create DLLs with debug information _and_ link them with 195 msvcrtd.dll instead of msvcrt.dll. 196 Beware: There are known problems with mixing DLLs in one 197 application, which are build against different runtimes. 198 Especially the index-to-file mapping used by 'unix-style' file 199 operation - _open() _pipe() etc. - breaks sometimes in strange 200 ways (for example the Gimp plug-in communication). 201] 202 203Required libraries (not build from svn) 204------------------ 205 libintl (gnu-intl), 206 207are available pre-built from the website mentioned above. 208 209Versioning 210---------- 211Instead of the Unix and auto* way of tracking versions and resolving 212dependencies (configure; make; make install) involving autoconf, 213automake, libtool and friends the MSVC build uses a different 214approach. 215 216The core of it's versioning is the file build/win32/module.defs. 217It contains entries of the form MODULE_VER, e.g.: 218 219 GLIB_VER = 2.0 220 LIBICONV_VER = 1.3 221 222and the placement of these modules defined as MODULE, e.g.: 223 224 GLIB = $(TOP)/glib 225 LIBICONV = $(TOP)/libiconv-$(LIBICONV_VER) 226 227whereas TOP is defined as the relative path from the respective 228module directory to your top build directory. Every makefile.msc 229needs to define TOP before including the common make file part 230make.msc, which than includes module.defs, like: 231 232TOP = ../.. 233!INCLUDE $(TOP)/glib/build/win32/make.msc 234 235(Taken from gtk+/gdk/makefile.msc) 236 237With this provision it is possible to create almost placement 238independent makefiles without requiring to 'install' the libraries and 239headers into a common place (as it is done on Unix, and as Tor does 240when producing his zipfiles with prebuilt GLib, GTK+ etc). 241 242Special Files 243------------- 244 config.h.win32.in : @XXX_MAJOR_VERSION@ needs to be replaced by 245the current version/build number. The resulting file is to be saved 246as 'config.h.win32'. This should be automatically done if a package 247gets build on the Unix platform. 248 249 makefile.msc.in : @XXX_MAJOR_VERSION@ to be replaced. Save as 250makefile.msc. 251 252 <module>.def : every function which should be used from the outside of 253a dll needs to be marked for 'export'. It is common that one needs to change 254these files after some api changes occured. If there are variables to be 255exported another mechanism is needed, like : 256 257 #ifdef G_OS_WIN32 258 # ifdef GDK_COMPILATION 259 # define GDKVAR __declspec(dllexport) 260 # else 261 # define GDKVAR extern __declspec(dllimport) 262 # endif 263 #else 264 # define GDKVAR extern 265 #endif 266 267 268 269Directory Structure 270------------------- 271all modules should be build in a common directory tree otherwise you 272need to adapt the file 'module.defs'. They are listed here in increasing 273dependencies order. 274 275<common rootdir without spaces> 276 | 277 +- glib 278 | | 279 | +- build : [this module lives in the SVN root dir] 280 | | +- win32 281 | | .\module.defs : defines (relative) locations of the headers 282 | | and libs and version numbers to be include 283 | | in dll names 284 | | .\make.msc : include by almost every 'makefile.msc' 285 | | 286 | | .\README.WIN32 : more information how to build 287 | | .\glibconfig.h.win32.in : similar to config.h.win32.in 288 | | .\makefile.msc : master makefile, sub dir makefiles should work 289 | | 290 | +- glib 291 | +- gmodule 292 | +- gthread : does _not_ depend on pthread anymore 293 | +- gobject 294 | 295 +- pango 296 | +- pango : 'native' build does not require extra libs and 297 | | includes the minimal required text renderer 298 | | (there is also a currently slightly broken FreeType2 299 | | based implementation for win32) 300 | +- modules (not yet build) 301 | 302 +- atk 303 | +- atk 304 | .\makefile.msc : build here 305 | 306 +- gtk+ 307 | | .\config.h.win32 : for all the below 308 | | 309 | +- gdk-pixbuf 310 | | .\gdk_pixbuf.rc.in : version resource for the DLLs. Needs 311 | | to be converted (filled with version info) 312 | | as described above. 313 | | 314 | +- gdk 315 | | | .\makefile.msc : some auto-generation is needed to build in the 316 | | | in the subdirectory 317 | | +- win32 318 | | 319 | +- gtk 320 321 | 322 +- gimp 323 | .\makefile.msc : master makefile to build The Gimp. The makefiles 324 | from the sub dirs should work stand alone, but than 325 | the user needs to know the build order 326 327 | 328 +- dia : additionally depends on libart_lgpl (in SVN) 329 | and libxml2 ( see http://www.xmlsoft.org/ ) 330 +- lib 331 +- app 332 +- objects 333 +- plug-ins 334 +- python 335 336