Skip to content

Instantly share code, notes, and snippets.

@elboulangero
Last active January 3, 2017 11:44
Show Gist options
  • Save elboulangero/bb31a33150d3f4170fe2b698536c104d to your computer and use it in GitHub Desktop.
Save elboulangero/bb31a33150d3f4170fe2b698536c104d to your computer and use it in GitHub Desktop.
/*
* Compile with:
* gcc $(pkg-config --cflags gtk+-3.0) *.c $(pkg-config --libs gtk+-3.0) -lm
*
* When Gtk is initialized through option group, launching the interactive
* debugger doesn't work.
* To test, just comment/uncomment the `#define USE_GTK_INIT`, rebuild, run:
*
* GTK_DEBUG=interactive ./a.out
*/
#include <stdlib.h>
#include <glib.h>
#include <gtk/gtk.h>
//#define USE_GTK_INIT
int
main(int argc, char *argv[])
{
#ifdef USE_GTK_INIT
/* Initialize using gtk_init() */
gtk_init(&argc, &argv);
#else
/* Initialize through option group */
GOptionContext *context = g_option_context_new("context");
GOptionGroup *option_group = gtk_get_option_group(TRUE);
g_option_context_add_group(context, option_group);
if (!g_option_context_parse(context, &argc, &argv, NULL)) {
g_print("Failed to parse options\n");
exit(EXIT_FAILURE);
}
#endif
/* Print Gtk version */
printf("Running against GTK+ %u.%u.%u\n",
gtk_get_major_version(),
gtk_get_minor_version(),
gtk_get_micro_version());
/* Run */
gtk_main();
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment