Running GTK+ Applications

Running GTK+ Applications — How to run and debug your GTK+ application

Running and debugging GTK+ Applications

Common commandline options

All GTK+ applications support a number of standard commandline options. These are removed from argv by gtk_init(). Modules may parse and remove further options. The X11 and Windows GDK backends parse some additional commandline options.

--gtk-module module A list of modules to load in addition to those specified in the GTK2_MODULES environment variable and the gtk-modules setting.

--g-fatal-warnings Make GTK+ abort on all warnings. This is useful to stop on the first warning in a debugger, if your application is printing multiple warnings. It's almost always best to start debugging with the first warning that occurs.

--gtk-debug options A list of debug options to turn on in addition to those specified in the GTK_DEBUG environment variable. This option is only available if GTK+ has been configured with --enable-debug=yes.

--gtk-no-debug options A list of debug options to turn off. This option is only available if GTK+ has been configured with --enable-debug=yes.

The following options are really used by GDK, not by GTK+, but we list them here for completeness nevertheless.

--class class Sets the program class; see gdk_set_program_class().

--name name Sets the program name.

--gdk-debug options A list of debug options to turn on in addition to those specified in the GDK_DEBUG environment variable. This option is only available if GTK+ has been configured with --enable-debug=yes.

--gdk-no-debug options A list of debug options to turn off. This option is only available if GTK+ has been configured with --enable-debug=yes.


Environment variables

GTK+ inspects a number of environment variables in addition to standard variables like LANG, PATH, HOME or DISPLAY; mostly to determine paths to look for certain files. The X11, Windows and Framebuffer GDK backends use some additional environment variables.

GTK_DEBUG If GTK+ has been configured with --enable-debug=yes, this variable can be set to a list of debug options, which cause GTK+ to print out different types of debugging information.

misc

Miscellaneous information

plugsocket

Cross-process embedding

text

Text widget internals

tree

Tree widget internals

updates

Visual feedback about window updates

keybindings

Keybindings

multihead

Working on multiple displays

modules

Loading of modules

geometry

Size allocation

icontheme

Icon themes

printing

Printing support

builder

GtkBuilder support

The special value all can be used to turn on all debug options.

GTK2_MODULES A list of modules to load. Note that GTK+ also allows to specify modules to load via a commandline option (--gtk-module) and with the gtk-modules setting.

GTK_MODULES A list of modules to load in addition to the ones in the GTK_MODULES variable.

Note that this environment variable is read by GTK+ 3 too, which may not have the same set of modules available for loading. Use GTK2_MODULES for modules that are only compatible with GTK+ 2.

GTK_PATH Specifies a list of directories to search when GTK+ is looking for dynamically loaded objects such as the modules specified by GTK_MODULES, theme engines, input method modules, file system backends and print backends. If the path to the dynamically loaded object is given as an absolute path name, then GTK+ loads it directly. Otherwise, GTK+ goes in turn through the directories in GTK_PATH, followed by the directory .gtk-2.0 in the user's home directory, followed by the system default directory, which is libdir/gtk-2.0/modules. (If GTK_EXE_PREFIX is defined, libdir is $GTK_EXE_PREFIX/lib. Otherwise it is the libdir specified when GTK+ was configured, usually /usr/lib, or /usr/local/lib.) For each directory in this list, GTK+ actually looks in a subdirectory directory/version/host/type Where version is derived from the version of GTK+ (use pkg-config --variable=gtk_binary_version gtk+-2.0 to determine this from a script), host is the architecture on which GTK+ was built. (use pkg-config --variable=gtk_host gtk+-2.0 to determine this from a script), and type is a directory specific to the type of modules; currently it can be modules, engines, immodules, filesystems or printbackends, corresponding to the types of modules mentioned above. Either version, host, or both may be omitted. GTK+ looks first in the most specific directory, then in directories with fewer components. The components of GTK_PATH are separated by the ':' character on Linux and Unix, and the ';' character on Windows.

Note that this environment variable is read by GTK+ 3 too, which makes it unsuitable for setting it system-wide (or session-wide), since doing so will cause either GTK+ 2.x applications or GTK+ 3 applications to see incompatible modules.

GTK_IM_MODULE Specifies an IM module to use in preference to the one determined from the locale. If this isn't set and you are running on the system that enables XSETTINGS and has a value in Gtk/IMModule, that will be used for the default IM module. This also can be a colon-separated list of input-methods, which GTK+ will try in turn until it finds one available on the system.

GTK_IM_MODULE_FILE Specifies the file listing the IM modules to load. This environment variable overrides the im_module_file specified in the RC files, which in turn overrides the default value libdir/gtk-2.0/2.10.0/immodules.cache (libdir has the same meaning here as explained for GTK_PATH).

GTK2_RC_FILES Specifies a list of RC files to parse instead of the default ones; see Resource Files.

Note that this environment variable is read by GTK+ 3 too, which makes it unsuitable for setting it system-wide (or session-wide), since doing so will cause either GTK+ 2.x applications or GTK+ 3 applications to see the wrong list of IM modules.

GTK_EXE_PREFIX If set, GTK+ uses $GTK_EXE_PREFIX/lib instead of the libdir configured when GTK+ was compiled.

GTK_DATA_PREFIX If set, makes GTK+ use $GTK_DATA_PREFIX instead of the prefix configured when GTK+ was compiled.

The following environment variables are used by GdkPixbuf, GDK or Pango, not by GTK+ itself, but we list them here for completeness nevertheless.

GDK_PIXBUF_MODULE_FILE Specifies the file listing the GdkPixbuf loader modules to load. This environment variable overrides the default value sysconfdir/gtk-2.0/gdk-pixbuf.loaders (sysconfdir is the sysconfdir specified when GTK+ was configured, usually /usr/local/etc.)

GDK_DEBUG If GTK+ has been configured with --enable-debug=yes, this variable can be set to a list of debug options, which cause GDK to print out different types of debugging information.

misc

Miscellaneous information

events

Show all events received by GDK

dnd

Information about drag-and-drop

xim

Information about XIM support

nograbs

Turn off all pointer and keyboard grabs

multihead

Information related to multiple screens

xinerama

Simulate a multi-monitor setup

cursor

Information about cursor objects (only win32)

draw

Information about drawing operations (only win32)

eventloop

Information about event loop operation (mostly Quartz)

The special value all can be used to turn on all debug options.

GDK_NATIVE_WINDOWS If set, GDK creates all windows as native windows. This can help applications that make assumptions about 1-1 correspondence between GDK windows and X11 windows.

XDG_DATA_HOME, XDG_DATA_DIRS GTK+ uses these environment variables to locate icon themes and MIME information. For more information, see Icon Theme Specification, the Shared MIME-info Database and the Base Directory Specification.

DESKTOP_STARTUP_ID GTK+ uses this environment variable to provide startup notification according to the Startup Notification Spec. Following the specification, GTK+ unsets this variable after reading it (to keep it from leaking to child processes). So, if you need its value for your own purposes, you have to read it before calling gtk_init().