LinuxCommandLibrary

glib-compile-resources

Compile XML resource descriptions into binary data

TLDR

Compile resources referenced in file.gresource.xml to a .gresource binary

$ glib-compile-resources [file.gresource.xml]
copy

Compile resources referenced in file.gresource.xml to a C source file
$ glib-compile-resources --generate-source [file.gresource.xml]
copy

Compile resources in file.gresource.xml to a chosen target file, with .c, .h or .gresource extension
$ glib-compile-resources --generate --target=[file.ext] [file.gresource.xml]
copy

Print a list of resource files referenced in file.gresource.xml
$ glib-compile-resources --generate-dependencies [file.gresource.xml]
copy

SYNOPSIS

glib-compile-resources [OPTION...] <resource.xml>

PARAMETERS

--target=FILE
    Output file for binary resource bundle (.gresource)

--sourcedir=DIRECTORY
    Prefix directory for resolving relative paths in XML

--generate
    Generate C source code for automatic resource registration (default without --target)

--generate-header
    Also generate matching C header file

--generate-source
    Generate C source code (deprecated alias for --generate)

--c-name=IDENTIFIER
    C identifier base name for generated code (default: resource name)

--manual-register
    Skip automatic registration in generated C code

--internal
    Mark resources for internal use only (not queryable)

--external-data=file.data
    Store named file data externally instead of embedding

--from-tmpfiles=FILE
    Read input in tmpfiles.d(5) format

--help
    Print help and exit

--version
    Print version information

DESCRIPTION

glib-compile-resources is a utility from the GLib library used to compile XML resource description files into binary resource bundles or C source/header files for embedding in applications.

It processes an XML file that lists files (such as images, UI definitions, shaders, or data) to bundle as GResource objects. These resources can then be loaded at runtime using GLib's GResource API, avoiding the need for external files during application distribution.

Common in GTK, GNOME, and other GNOME Platform apps, it simplifies deployment by embedding assets directly into executables or shared libraries. The tool supports two main modes: generating a binary .gresource file (via --target) for loading with g_resources_register(), or producing C code (via --generate) that registers resources automatically at link time.

Relative paths in the XML are resolved relative to the current directory or a specified --sourcedir. Compression is automatic for eligible files, reducing bundle size. It's essential for modern desktop app development, ensuring self-contained binaries.

TYPICAL USAGE

Binary: glib-compile-resources --sourcedir=. --target=myapp.gresource myapp.gresource.xml
C source: glib-compile-resources --generate --c-name my_resources --sourcedir=. myapp.gresource.xml > myapp-resources.c

HISTORY

Introduced in GLib 2.32 (March 2011) alongside the GResource API to support embedded resources in Flatpak and GNOME apps. Evolved with GLib releases for better compression, external data, and tmpfiles support.

SEE ALSO

gresource(7), glib-compile-schemas(1), gtk4-builder-tool(1)

Copied to clipboard