Getting Started with Gtk4 on Ubuntu PopOS! 22.04

Free Folk Create Free Software

Install Cambalache 0.12 (optional)

Cambalache is a new RAD tool for Gtk 4 and 3 with a clear MVC design and data model first philosophy. This translates to a wide feature coverage with minimal/none developer intervention for basic support.

See the following link for further instructions on setting up Cambalache.

https://blogs.gnome.org/xjuan/2023/06/16/cambalache-0-12-0-released/

At the moment, I am having trouble getting Cambalache compiled from source on my machine. I have not tested other installation methods.

More details are here if curious: https://gitlab.gnome.org/jpu/cambalache/-/issues/180

Getting a Ubuntu 22.04 desktop environment ready for compiling libgtkmm

To install libgtkmm-4.0 on PopOS! 22.04, we will need to configure and build it manually from source since it isn't available on Ubuntu's PPA 22.04 as a package.

From some public research, PopOS! 24.04 will ease the setup process without having to build from scratch. I personally couldn't wait and wanted to get up and running with gtk4 ASAP. Gtk4 has some super improvements and you may view some of these improvements by searching with your favorite search engine.

Install Build Dependencies for gtkmm-4.0

To build gtkmm-4.0, I followed this documentation from Terminalroot.com, but I added up-to-date packages in this article. Plus, I am using PopOS! 22.04 for this tutorial and ran into some other issues while getting gtkmm-4.0 up and running.

Determining what deps you need to install gtk4 is located here: https://gnome.pages.gitlab.gnome.org/gtkmm-documentation/chapter-installation.html

sudo apt install build-essential git g++ autotools-dev libgtkmm-3.0-dev \
libgtkmm-3.0-doc mm-common libgtk-4-bin \
libgtk-4-common libgtk-4-dev libgtk-4-doc pkg-config \
docbook-xsl

Next, we need SigC++-3.4.0

wget http://mirror.accum.se/pub/gnome/sources/libsigc++/3.4/libsigc++-3.4.0.tar.xz
tar Jxvf libsigc++-3.4.0.tar.xz
cd libsigc++-3.4.0.tar.xz
./autogen.sh --prefix/usr/local
make
sudo make install
cd ..

Next, we install glibmm-2.68

wget https://download.gnome.org/sources/glibmm/2.68/glibmm-2.68.2.tar.xz
tar Jxvf glibmm-2.68.2.tar.xz
cd glibmm-2.68.2/
./autogen.sh --prefix=/usr
make
sudo make install
cd ..

Next, we compile and install cairomm

git clone git://git.cairographics.org/git/cairomm
cd cairomm
./autogen.sh --prefix=/usr
make
sudo make install
cd ..

And finally, we compile and install pangomm-2.50

wget https://download.gnome.org/sources/pangomm/2.50/pangomm-2.50.0.tar.xz
tar Jxvf pangomm-2.50.0/
cd pangomm-2.50.o/
./autogen.sh --prefix=/usr
make
sudo make install
cd ..

Compile and Install gtkmm-4.6.1

Note: Installing Gtkmm-4.9.3 resulted in a version mismatch on Ubuntu PopOS! 22.04.

configure: error: Package requirements (giomm-2.68 >= 2.68.0 pangomm-2.48 >= 2.50.0 cairomm-1.16 >= 1.15.4 gtk4 >= 4.9.3 gdk-pixbuf-2.0 >= 2.35.5) were not met:
Requested 'gtk4 >= 4.9.3' but version of GTK is 4.6.9

Tip: To list the available libgtk versions, Mark Baker on stackoverflow shared how to view this.
dpkg -l libgtk* | grep -e '^i' | grep -e 'libgtk-*[0-9]'

wget https://download.gnome.org/sources/gtkmm/4.6/gtkmm-4.6.1.tar.xz
wget https://download.gnome.org/sources/gtkmm/4.6/gtkmm-4.6.1.sha256sum
sha256sum -c --ignore-missing gtkmm-4.6.1.sha256sum

If it appears: gtkmm-4.6.1.tar.xz: OK, everything is ok and we can proceed, if not, download the files again.

tar Jxvf gtkmm-4.6.1.tar.xz
cd gtkmm-4.6.1
./autogen.sh --prefix=/usr
make
sudo make install

Checking libsigc-3.0.so

Run the command:

ls /usr/lib/libsigc-3*

If you don’t find anything, CREATE these symlinks:

sudo ln -s /usr/local/lib/libsigc-3.0.so.0.0.0 /usr/lib/libsigc-3.0.so.0.0.0
sudo ln -s /usr/local/lib/libsigc-3.0.la /usr/lib/libsigc-3.0.la
sudo ln -s /usr/local/lib/libsigc-3.0.so /usr/lib/libsigc-3.0.so
sudo ln -s /usr/local/lib/libsigc-3.0.so.0 /usr/lib/libsigc-3.0.so.0

This will solve problems when running the program.

Next, we probably want to get started with GNU's Autotools

Autotools cleans up the build process and makes building, distributing and installing C++ apps a breeze.

sudo apt install autotools

After installation, we build our example application that includes our new gtkmm 4.6.1.

base.cpp

Our example base.cpp application that uses gtkmm wrapper.

#include <gtkmm.h>
class MyWindow : public Gtk::Window
{
public:
 MyWindow();
};
MyWindow::MyWindow()
{
 set_title("A HTMX Web Browser with GTK4!");
 set_default_size(400, 400);
}
int main(int argc, char* argv[])
{
 auto app = Gtk::Application::create("org.gtkmm.examples.base");
 return app->make_window_and_run<MyWindow>(argc, argv);
}

touch configure.ac

configure.ac

AC_INIT([cplusplus_gtk4_app_skeleton], [0.1], [[email protected]])
AC_PREREQ([2.68]) # autoconf version >= 2.68
AC_CONFIG_AUX_DIR([build-aux]) # Auxiliary files go here
AM_INIT_AUTOMAKE
AC_PROG_CXX
AC_CONFIG_FILES([Makefile])
PKG_CHECK_MODULES([cplusplus_gtk4_app_skeleton], [gtkmm-4.0 >= 4.6.1])
# Put various checks and such here.
AC_OUTPUT

touch Makefile.am

Makefile.am

AUTOMAKE_OPTIONS = gnu dist-xz  # sets automake standards
bin_PROGRAMS = cplusplus_gtk4_app_skeleton
AM_CXXFLAGS = $(shell pkg-config --cflags gtkmm-4.0)
LIBS = $(shell pkg-config --libs gtkmm-4.0)
cplusplus_gtk4_app_skeleton_SOURCES = base.cpp

Let autotools do the work!

In the root of your project, we setup autotools and initialize the project.

aclocal
autoconf
automake

Shipping Your GNU Cplusplus App (optional)

Creating the binaries and shipping them is ease as pie!

make dist

Install Your Free GNU Cplusplus App (optional)

Installation is breezy lemon squeezy!

sudo make install

Building Your Cplusplus App

After changes are made to our program, we need to re-build the binary and launch it from command line.

./configure
make
./cplusplus_gtk4_app_skeleton

Financial Support & Donations

I mainly debug code, drive, yak shave and deep dive into research for Linux base operating systems.

I am a Free Software Associate (FSF), privacy advocate and Cosmopolitan that enjoys philosophie, meta-physics, hacking and debugging computer hardware/software.

https://liberapay.com/oDinZu/

  • Liberapay is a recurrent donations platform
  • Run by a non-profit organization
  • Source code is public
  • No commission fee
  • ~5% payment processing fee

Sources

  1. Autotools: https://earthly.dev/blog/autoconf/
  2. Build Dependencies for Gtk4: https://gnome.pages.gitlab.gnome.org/gtkmm-documentation/chapter-installation.html
  3. Cairomm: https://www.cairographics.org/cairomm/
  4. DocBook: https://help.ubuntu.com/community/DocBook
  5. Cambalache: https://blogs.gnome.org/xjuan/2023/06/16/cambalache-0-12-0-released/
  6. Gstreamer: https://gstreamer.freedesktop.org/documentation/installing/on-linux.html?gi-language=c
  7. GTK3 & GTK4: https://www.gtk.org/docs/installations/linux/
  8. Gtkmm C++ Interpreter: https://gtkmm.org/en/download.html#Binary
  9. How-to Install Gtkmm-4 on Ubuntu 22.04: https://terminalroot.com/how-to-install-gtkmm-4-on-ubuntu-2204/
  10. LibsigC++ 3.4 Download: http://mirror.accum.se/pub/gnome/sources/libsigc++/
  11. Linux Gtk Glade Programming Part 1: https://www.youtube.com/watch?v=g-KDOH_uqPk
  12. Stackoverflow Mark Baker - Version of GTK on Ubuntu: https://stackoverflow.com/questions/126141/how-do-you-find-out-which-version-of-gtk-is-installed-on-ubuntu
  13. Cambalache Debugging on Ubuntu 22.04: https://gitlab.gnome.org/jpu/cambalache/-/issues/180
CharlesCharles