Ade Malsasa Akbar contact
Senior author, Open Source enthusiast.
Saturday, December 4, 2021 at 22:44

This tutorial will explain how to install a full GTK version 3 software development kit on Parabola GNU/Linux computer operating systems. This will include the necessary components as well as the editor, compiler and documentation. Finally, we hope this helps people to develop more desktop free software. Now let's go!


Subscribe to UbuntuBuzz Telegram Channel to get article updates.

This tutorial is for Parabola so if you want for Debian and Ubuntu, please visit Setup C/GTK for Ubuntu Tutorial instead.

About GTK

GTK, formerly called GTK+, is a choice of computer software libraries to develop graphical user interface applications and desktop environments. GNOME, Gimp and PureOS (Librem Computers) are the best examples of software products created with GTK. With GTK, one can create cross-platform desktop applications with C programming language (other languages also supported). The name GTK itself stands for Gimp Toolkit and in turn is originated from GNU Operating System. Visit its official website at https://www.gtk.org.

Components of GTK:

  1. GTK
  2. Glib
  3. Pango
  4. Gdk-pixbuf
  5. ATK
  6. Gobject-introspection
  7. Epoxy


List of Programs To Install

Programs we will install as a full software development kit:

1. The seven components of GTK above.

2. GCC, the C compiler.

3. Geany, the integrated development environment. 

4. Glade, the interface designer. 

5. Devhelp, the documentation reader. 


Install GTK on Parabola

First, install all GTK components.

# pacman -S gtk3 glib2 pango atk gobject-introspection gdk-pixbuf2 libepoxy

Then, install GTK documentation and examples.
# pacman -S gtk3-docs gtk3-demos

Then, install the C compiler.
# pacman -S gcc
 
Then, install the interface builder.
# pacman -S glade

Finally, install the documentation reader.
# pacman -S devhelp

Installed Tools


You will get a full set of GTK3 software development kit including the editor, compiler, documentation, and even the code examples. 

Geany editor:

GTK 3 Documentation viewed using DevHelp:


GTK 3 Demos or code examples:

GTK3 Widget Factory: 




Write Your First Program


This is a program taken from the official GTK+ Documentation. Write this, save it as gui.c, and compile it on your Terminal Emulator, and it should result in a nice window showing with a Hello World button. If you click the button, the window disappears and a Hello World message printed on the Terminal.
// gui.c - Copied from https://developer.gnome.org/gtk3/stable/gtk-getting-started.html
#include <gtk/gtk.h>

static void
print_hello (GtkWidget *widget,
             gpointer   data)
{
  g_print ("Hello World\n");
}

static void
activate (GtkApplication *app,
          gpointer        user_data)
{
  GtkWidget *window;
  GtkWidget *button;
  GtkWidget *button_box;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);

  button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  gtk_container_add (GTK_CONTAINER (window), button_box);

  button = gtk_button_new_with_label ("Hello World");
  g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
  g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
  gtk_container_add (GTK_CONTAINER (button_box), button);

  gtk_widget_show_all (window);
}

int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}


Compile:

$ gcc `pkg-config --cflags gtk+-3.0` -o gui gui.c `pkg-config --libs gtk+-3.0`

Execute:
$ ./gui

The result:


Happy hacking!


This article is licensed under CC BY-SA 3.0.