Installing GTK Dependencies

Referring to the official Setting up GTK for Linux page, how do I install the dependencies?

I have used the download icons and chosen the latest versions. Now I have a bunch of .xz and .gz files but I have absolutely no idea where to extract them or how to ensure that they are actually installed properly on my system.

Is there a guide somewhere that I have missed that explains how to install these 7 archives?

image

Hi,

Well, usually it’s very rare that people have to install gtk from the *.tar.xz.
Those are source files, you need to properly setup a compiler to generate the libraries. It’s usually done by the Linux distribution providers, which offer pre-compiled binaries, installable by their package managers.

Which Linux distribution are you using?

Also, why do you need to install gtk? Do you want to develop your own application? or install an existing one that depends on gtk?

1 Like

Hi. I’m using Kubuntu (version 20 I believe). I would like to be able to port some of my Windows GUI util apps over to Linux. I’ve only ever built command line apps on Linux before so I thought I’d give GTK a try.

So basically I need to knock up some simple dialog applications that have buttons, list boxes/rich text edit controls and the likes.

OK. First you have to look for the version of gtk used by your apps, is it gtk3 or gtk4?
Kubuntu 20 is already quite old, I don’t even know if it supports gtk4…

If you need gtk3 then it’s easy to install the development headers with sudo apt-get install libgtk-3-dev, that should be enough.

You may need to install further *-dev packages, depending on what your app needs. But then better ask on an Ubuntu-specific forum, they will know how to proceed.

Not having much luck here unfortunately.

I tried install gtk3 as suggested:
sudo apt-get install libgtk-3-dev

Then I tried building the Hello World example using the docs here

paul@paul-Linux:~/work/gtk$ gcc $(pkg-config --cflags gtk3) -o main main.cpp $(pkg-config --libs gtk3)
Package gtk3 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk3.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk3' found
Package gtk3 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk3.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk3' found
main.cpp:1:10: fatal error: gtk/gtk.h: No such file or directory
    1 | #include <gtk/gtk.h>
      |          ^~~~~~~~~~~
compilation terminated.

I tried the below command in case I was missing any dependencies:
sudo apt-get install build-essential gnome-devel

…but gcc isn’t finding the header files. Do I need to go looking for gtk.pc and manually update the PKG_CONFIG_PATH environment var?

UPDATE: So I found the GTK3 Getting Started docs and changed my command line as follows:

paul@paul-Linux:~/work/gtk$ gcc `pkg-config --cflags gtk+-3.0` -o main main.cpp `pkg-config --libs gtk+-3.0`
main.cpp: In function ‘void activate(GtkApplication*, gpointer)’:
main.cpp:23:3: error: ‘gtk_window_set_child’ was not declared in this scope; did you mean ‘gtk_window_set_role’?
   23 |   gtk_window_set_child (GTK_WINDOW (window), button);
      |   ^~~~~~~~~~~~~~~~~~~~
      |   gtk_window_set_role
main.cpp: In function ‘int main(int, char**)’:
main.cpp:35:49: error: ‘G_APPLICATION_DEFAULT_FLAGS’ was not declared in this scope; did you mean ‘G_APPLICATION_GET_CLASS’?
   35 |   app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
      |                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                 G_APPLICATION_GET_CLASS

So it is compiling now… Now I just have to figure out what is different between the GTK3 and GTK4 HelloWorld example I guess. The GTK3 example built and ran just fine.

Or… I see if it is possible to get GTK4 onto my system:

paul@paul-Linux:~/work/gtk$ sudo apt-get install libgtk-4-dev
[sudo] password for paul: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package libgtk-4-dev

… but that doesn’t look promising either

You literally cannot use a GTK4 code example with GTK3. The major version didn’t change for fun: there is a whole migration guide.

If you distribution does not ship with GTK4 you have the option to download GNOME Builder from Flathub and then build against the GNOME SDK.

You also probably want to look at the Getting Started tutorial.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.