GTK+ 3 Glade C Programming Template Files

A set of template files for starting new GTK+ 3 C programming language projects using Glade for the GUI. The structure of the template directory separates the C source code and Glade files into their own sub-directories with a makefile in the main directory.

These template files make it easier to manage a project by separating the C source code and the Glade files. The makefile allows source code files to be added to the project easily as the project grows.

This article extends simple GTK+ 3 C programming using Glade and compiling by entering compile commands manually, to a better structured project and using a makefile.

Structure of the GTK+ 3 Glade Template Directory

The template has a src directory that contains the C source files for the project, and a glade directory that contains the Glade files. The makefile is found in the root directory of the template as shown in the image below.

GTK+ 3 Glade C Programming Template
GTK+ 3 Glade C Programming Template

GTK+ 3 and Glade Template Source Code

The template directory contains the following source code that can be copied to create a set of template files for your own projects.

The Makefile

Below is the contents of the file called makefile which must be placed in the root directory of the project.

Change the name template_app at the top of the file to the name of your project. This will be the name of the executable file that is generated after compiling.

Modify the makefile when new C source code files are added to the project so that the new files are compiled and linked.

Main C Source Code File

In the src directory, create a file called main.c and copy the following code to it.

All C source code files that are added to the project can be placed in the src directory. Glade files that are used in the project are placed in the glade directory and accessed as such in the C source code as the following line of code from above shows.

Glade File

A new glade file can be created in the Glade editor or the code below can be copied to a file called window_main.glade in the glade directory.

All new Glade files added to the project are to be put into the glade directory.

Building the GTK+ 3 Glade C Programming Template Project

Open a terminal window and change to the project directory. To build the project, enter make in the terminal window. This assumes that the correct software and libraries have been installed.

Build the project:

Clean the project — delete object and executable files:

If an error message appears when you try to build the project using make, open the make file in a text editor and be sure to replace the spaces that are used to indent text in the file with tab characters by using the Tab key. A typical error message is:

This indicates that the following indented line in the make file listing is indented with spaces instead of a tab character:

 

11 thoughts on “GTK+ 3 Glade C Programming Template Files”

  1. These notes have been very helpful. I did a lot of searching and only found older tutorials that did not apply anymore. “… deprecated” was the most familiar word I would see. Thank you for reconnecting me to Linux development.

  2. Excellent tutorial, I’m just getting started with GTK after years of Visual Studio and the transition is not easy, this just gave me a real jump start, thanks for your help.

  3. Please can you make tutorial on simple app which use some input and output for ex. add two numbers and display result tnx

  4. Thanks to this tutorial, I was finally able to use Glade with GTK+ 3 and not just with GTK+ 2. Thank you very much. I am very grateful for the help.

Leave a Reply

Your email address will not be published. Required fields are marked *