Here is a quick guide to compiling a simple GTK program that uses the glade3 interface builder (paraphrased from http://www.gnome.org/~newren/tutorials/developing-with-gnome/html/index.html).
1. Firstly, install Glade3, which as seen below, bears similarities to other interface builders.
2. Note that the OK button has a callback function 'ok_button_clicked' connected to the 'clicked' signal.
3. Save the file as a .glade file. Here, I've called it 'example.glade'
4. Create the following C source file (I've called it 'example.c'). Note the callback function that's been written.
- Code: Select all
#include <gtk/gtk.h>
#include <glade/glade.h>
void ok_button_clicked (GtkWidget *widget, gpointer user_data)
{
printf("Thanks for trying out my program.\n");
gtk_main_quit();
}
int main(int argc, char *argv[])
{
GladeXML *xml;
GtkWidget *widget;
gtk_init(&argc, &argv);
/* load the interface */
xml = glade_xml_new ("example.glade", NULL, NULL);
/* connect the signals in the interface */
/* Have the ok button call the ok_button_clicked callback */
widget = glade_xml_get_widget(xml, "OKButton");
g_signal_connect(G_OBJECT (widget), "clicked",
G_CALLBACK (ok_button_clicked),
NULL);
/* Have the delete event (window close) end the program */
widget = glade_xml_get_widget (xml, "MainWindow");
g_signal_connect(G_OBJECT (widget), "delete_event",
G_CALLBACK (gtk_main_quit), NULL);
/* start the event loop */
gtk_main();
return 0;
}
5. Compile this file using the following command.
- Code: Select all
gcc example.c -o example `pkg-config --cflags --libs libglade-2.0`
6. And voila




