gresource
Manage GLib resource bundles
SYNOPSIS
gresource command [options] [arguments]
PARAMETERS
compile
Compiles an XML resource description file into a binary GResource bundle or C source code.
list
Lists the virtual paths of all resources contained within a GResource bundle.
cat
Prints the content of a specified resource from a GResource bundle to standard output.
extract
Extracts a specified resource from a GResource bundle to a file on the filesystem.
--output=FILE, -o FILE
Specifies the output file for compiled resources (used with compile) or extracted resources (used with extract). Defaults to standard output.
--generate-header
Used with compile to generate a C header file containing declarations for the compiled resources.
--generate-source
Used with compile to generate a C source file that can be compiled and linked directly into an application.
--dependency-file=FILE
Used with compile to generate a Makefile-style dependency file, listing all input files required to build the resource bundle.
--manual-aliases
Used with compile to prevent gresource from automatically generating resource aliases based on filenames. Aliases must then be explicitly defined in the XML.
--section=PATH
Used with list to filter the output, showing only resources under a specific virtual path prefix.
--gresource-path=PATH
Specifies an additional directory to search for GResource bundles at runtime when using commands like list or cat.
--version
Displays the version information for the gresource command.
--help
Displays help information and usage details for the gresource command.
DESCRIPTION
The gresource command-line utility, part of the GLib library, facilitates the management of GResources. These are binary containers designed to bundle various application-specific data, such as UI definitions (e.g., GTK+ .ui files), icons, images, CSS stylesheets, and translations. Its primary function is to compile an XML resource description (a .gresource.xml file) into a binary .gresource file or directly into C source code that can be linked with an application. This method simplifies application deployment by embedding or bundling all necessary assets, reducing reliance on external files and potentially improving startup performance. Beyond compilation, gresource also offers commands to list, extract, or display the content of resources from existing .gresource files, proving invaluable for inspection and debugging during development.
CAVEATS
gresource is primarily a build-time utility; while list and cat can inspect runtime resources, its main use is compilation. The .gresource.xml format is specific to GLib and defines virtual paths. Resource paths are case-sensitive and must be consistently handled. It requires the GLib development headers and libraries to be available on the system for compilation.
<B>RESOURCE PATHS</B>
GResources use a virtual path system, typically starting with a leading slash (e.g., /org/example/app/ui/mainwindow.ui). These paths are crucial for defining resources in the .gresource.xml file and for accessing them from application code using functions like g_resources_lookup_data() or g_resources_open_stream().
<B>INTEGRATION WITH BUILD SYSTEMS</B>
In modern build systems like Meson or CMake, gresource is frequently invoked automatically through specialized modules or custom commands (e.g., gnome.compile_resources in Meson). This integration ensures that .gresource files or compiled C source code are seamlessly generated as an integral part of the application's overall build process.
HISTORY
GResources were introduced in GLib 2.32 (around 2012) to standardize and simplify resource management for applications, particularly those built with GTK+ and GLib. Prior to this, applications often managed assets as loose files, which complicated deployment and could lead to runtime issues. The gresource command-line tool was developed alongside this feature, providing essential capabilities for compiling resources into a single binary blob, thereby improving application startup times and streamlining distribution by bundling all necessary assets.
SEE ALSO
pkg-config(1), glib-compile-schemas(1), gtk-builder-tool(1)