LinuxCommandLibrary

gresource

Manage GLib resource bundles

SYNOPSIS

gresource [OPTION...] COMMAND [ARGS...]

PARAMETERS

-h, --help
    Print help and exit

-V, --version
    Print version and exit

-q, --quiet
    Suppress non-error output

--section=SECTION
    Show only specified sections (repeatable); applies to list/sections

--target=FILE
    Store output in FILE (compile/extract)

--sourcedir=DIR
    Root dir for relative paths in XML (compile)

--generate
    Generate C source from UI/CSS/XML/etc. files (compile)

--generate-source
    Generate plain C source code (compile)

--generate-header
    Generate C header (compile)

--c-name=NAME
    C identifier prefix for generated code (compile, default from filename)

--manual
    Skip if target newer than inputs (compile)

--internal
    Mark resource as internal (no GObject init needed; compile)

--format=[xml|binary|bytes]
    Output format for extract (default xml)

DESCRIPTION

gresource is a versatile command-line tool from the GLib library for working with GResource, a framework that bundles files like images, XML UI descriptions, CSS, and translations into compact binary resources or C source code. This enables embedding assets directly into executables, reducing runtime file dependencies and easing deployment for GTK+, GNOME, and other GLib-based applications.

Key uses include compiling XML manifests (listing files with optional aliases and sections) into .gresource files linkable via g_resources_register(), or generating C headers/sources for static inclusion. Developers define resources in XML like <gresource root="/org/gtk/libgtk"> with <file> entries. The tool supports sections for organizing resources and preconditions for conditional inclusion.

Common in build systems (Meson, CMake), it streamlines asset handling, supports i18n via gettext, and aids cross-platform development. Extract, list, and sections subcommands aid debugging and inspection. Widely used since GLib 2.32, it's essential for modern desktop app resource management.

CAVEATS

Command-specific options only apply to relevant subcommands; XML must validate against GResource schema; generated C code requires and linking with libgio.

SUBCOMMANDS

compile <XML> [<files>...]: Build .gresource or C code.
extract <FILE> <PATH>: Dump resource entry.
list <FILE>: Enumerate entries.
sections <FILE>: Show sections.

EXAMPLE

gresource compile --target=app.gresource app.gresource.xml
Compiles XML to binary resource.

HISTORY

Introduced in GLib 2.32 (March 2011) with GResource framework to replace ad-hoc bundling in GNOME/GTK apps; unified prior glib-compile-resources functionality; actively maintained in modern GLib versions.

SEE ALSO

glib-compile-resources(1), gio(1), gtk4-builder-tool(1)

Copied to clipboard