1 Toolchain/Compiler requirements
4 GLib requires a toolchain that supports C99.
6 GLib contains some fall back code that allows supporting toolchains that are not
9 GLib makes some assumptions about features of the C library and C preprocessor,
10 compiler and linker that may go beyond what C99 mandates. We will use features
11 beyond C99 if they are substantially useful and if they are supported in a wide
14 In general, we are primarily interested in supporting these four compilers:
21 This is in keeping with our goal of primarily targetting GNU/Linux, Windows and
22 Mac OS, along with Free Software POSIX-compliant operating systems. See
23 [Supported platforms](./supported-platforms.md) for a bit more information and
26 In particular, we are interested in MSVC because, although there are other
27 compilers which target Windows, they do not output debugging information that is
28 compatible with MSVC. In interest of usability, we want users of GLib to be
29 able to debug GLib along with their own code while using MSVC as their
30 development environment.
32 At any given time, GLib may work with mingw32 (from mingw.org) but it is not
33 specifically supported. Politics aside, it seems that mingw.org is mostly
34 dormant and, at this point, all of the big distributions have switched over to
35 mingw32-w64. In several cases, mingw.org has been missing APIs that we’ve
36 wanted to use and upstream has not been responsive about adding them.
38 GLib will attempt to remain compatible with other compilers, but some ‘extra
39 features’ are assumed. Those are detailed below.
41 GLib additionally requires Python 3 to build.
48 GLib requires C99 ``__VA_ARG__`` support for both C and C++ compilers.
50 Symbol visibility control
53 _Not a hard requirement._
55 When available, GLib uses `__attribute__((visibility("hidden")))` and the
56 `-fvisibility=hidden` compiler option to control symbol visibility, and the
57 `-Bsymbolic-functions` linker flag.
59 Builtin atomic operations
62 _Not a hard requirement._
64 GLib will fall back to using a mutex-based implementation if atomic builtins are
67 C99 printf and positional parameters
70 _Not a hard requirement._
72 GLib can be built with an included printf implementation (from GNUlib) if the
73 system printf is deficient.
75 Constructors and destructors
80 GLib can work with pragma-based, as well as with attribute-based constructor
81 support. There is a fallback for MSVC using a `DllMain()` instead.
83 `va_list` pass-by-reference
88 GLib depends on the ability to pass-by-reference a `va_list`, as mandated in
89 C99 § 7.15: “It is permitted to create a pointer to a `va_list` and pass that
90 pointer to another function, in which case the original function may make
91 further use of the original list after the other function returns.”
93 Support for `static inline`
98 GLib depends on implementation of the `inline` keyword as described by
101 GLib further assumes that functions appearing in header files and marked
102 `static inline`, but not used in a particular compilation unit will:
104 * not generate warnings about being unused
105 * not be emitted in the compiler’s output
107 It is possible that a compiler adheres to C99 § 6.7.4 but not to GLib’s further
108 assumptions. Such compilers may produce large numbers of warnings or large
109 executables when compiling GLib or programs based on GLib.
111 Support for `alloca()`
116 Your compiler must support `alloca()`, defined in `<alloca.h>` (or `<malloc.h>`
117 on Windows) and it must accept a non-constant argument.
119 (C11) support for type redefinition
122 **This requirement has been temporarily suspended (on account of OpenBSD
123 carrying an old version of gcc) but it will probably return in the future.**
125 Your compiler must allow “a typedef name [to] be redefined to denote the same
126 type as it currently does”, as per C11 §6.7, item 3.
133 Some of our enum types use `1<<31` as a value. We also use negative values in
134 enums. We rely on the compiler to choose a suitable storage size for the enum
135 that can accommodate this.
137 Selected C99 features
142 Starting with GLib 2.52 and GTK 3.90, we will be using the following C99
143 features where appropriate:
146 * Designated initializers
149 Function pointer conversions
154 GLib heavily relies on the ability to convert a function pointer to a `void*`
155 and back again losslessly. Any platform or compiler which doesn’t support this
156 cannot be used to compile GLib or code which uses GLib. This precludes use of
157 the `-pedantic` GCC flag with GLib.
162 _Hard requirement since GLib 2.67.x._
164 GLib [requires a C99 `stdint.h`](https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1675)
165 with all the usual sized integer types (`int8_t`, `uint64_t` and so on),
166 believed to be supported by all relevant Unix platforms/compilers, as well as
167 Microsoft compilers since MSVC 2013.