Gtk4-tutorial/gfm/sec2.md

182 lines
6.3 KiB
Markdown
Raw Normal View History

2021-01-13 12:59:15 +01:00
Up: [Readme.md](../Readme.md), Prev: [Section 1](sec1.md), Next: [Section 3](sec3.md)
# Installation of gtk4 to linux distributions
2020-12-21 13:12:05 +01:00
This section describes how to install gtk4 into linux distributions.
However, I only have an experience to install it to ubuntu 20.10.
Probably you need more than the explanation below.
2020-12-22 03:30:06 +01:00
This tutorial including this section is without any warranty.
If you install gtk4 to your computer, do it at your own risk.
2020-12-22 03:30:06 +01:00
## Prerequisite
2020-12-22 03:30:06 +01:00
- Ubuntu 20.10. Maybe other versions of late years or other distribution might be OK.
- Packages for development such as gcc, meson, ninja, git, wget and so on.
- Dev packages necessary for each software below.
2020-12-22 03:30:06 +01:00
## Installation target
2020-12-22 03:30:06 +01:00
I installed gtk4 under the directory `$HOME/local`.
This is a private user area.
2020-12-22 03:30:06 +01:00
Don't install it to `/usr/local` which is the default.
It is used by ubuntu applications, which are not build on gtk4.
Therefore, the risk is high and probably bad things will happen.
Actually I did it and I needed to reinstall ubuntu.
2020-12-22 03:30:06 +01:00
## Glib installation
2020-12-22 03:30:06 +01:00
Ubuntu includes glib but its version is not high enough to build gtk4.
Glib 2.66.0 or higher is required.
At present (Jan/2021), its latest version is 2.67.2.
I installed 2.67.1 which was the latest version at that time.
Download glib source files from the repository, then decompress and extract files.
2020-12-22 03:30:06 +01:00
$ wget https://download.gnome.org/sources/glib/2.67/glib-2.67.1.tar.xz
$ tar -Jxf glib-2.67.1.tar.xz
2020-12-22 03:30:06 +01:00
Some packages are required to build glib.
You can find them if you run meson.
2020-12-22 03:30:06 +01:00
$ meson --prefix $HOME/local _build
2020-12-22 03:30:06 +01:00
Use apt-get and install the prerequisites.
For example,
2020-12-22 03:30:06 +01:00
$ sudo apt-get install -y libpcre2-dev libffi-dev
2020-12-22 03:30:06 +01:00
After that, compile glib.
2020-12-22 03:30:06 +01:00
$ rm -rf _build
$ meson --prefix $HOME/local _build
$ ninja -C _build
$ ninja -C _build install
2020-12-22 03:30:06 +01:00
Set sevral environment variables so that the glib libraries installed can be used by build tools.
Make a text file below and save it as `env.sh`
2020-12-22 03:30:06 +01:00
# compiler
CPPFLAGS="-I$HOME/local/include"
LDFLAGS="-L$HOME/local/lib"
PKG_CONFIG_PATH="$HOME/local/lib/pkgconfig:$HOME/local/lib/x86_64-linux-gnu/pkgconfig"
export CPPFLAGS LDFLAGS PKG_CONFIG_PATH
# linker
LD_LIBRARY_PATH="$HOME/local/lib/x86_64-linux-gnu/"
PATH="$HOME/local/bin:$PATH"
export LD_LIBRARY_PATH PATH
# gsetting
export GSETTINGS_SCHEMA_DIR=$HOME/local/share/glib-2.0/schemas
2020-12-22 03:30:06 +01:00
Then, use . (dot) or source command to include these commands to the current bash.
2020-12-22 03:30:06 +01:00
$ . env.sh
2020-12-22 03:30:06 +01:00
or
2020-12-22 03:30:06 +01:00
$ source env.sh
2020-12-22 03:30:06 +01:00
This command carries out the commands in `env.sh` and changes the environment variables above in the corrent shell.
2020-12-22 03:30:06 +01:00
## Pango installation
2020-12-22 03:30:06 +01:00
Download and untar.
2020-12-22 03:30:06 +01:00
$ wget https://download.gnome.org/sources/pango/1.48/pango-1.48.0.tar.xz
$ tar -Jxf pango-1.48.0.tar.xz
2020-12-22 03:30:06 +01:00
Try meson and check the required packages.
Install all the prerequisites.
Then, compile and install pango.
2020-12-22 03:30:06 +01:00
$ meson --prefix $HOME/local _build
$ ninja -C _build
$ ninja -C _build install
2020-12-22 03:30:06 +01:00
It installs Pnago-1.0.gir under `$HOME/local/share/gir-1.0`.
If you installed pango without --prefix option, then it would be located at `/usr/local/share/gir-1.0`.
This directory (/usr/local/share) is used by applications.
They find the directory by the environment variable `XDG_DATA_DIRS`.
It is a text file which keep the list of 'share' directoryes like `/usr/share`, `usr/local/share` and so on.
Now `$HOME/local/share` needs to be added to `XDG_DATA_DIRS`, or error will occur in the later compilation.
2020-12-22 03:30:06 +01:00
$ export XDG_DATA_DIRS=$HOME/local/share:$XDG_DATA_DIRS
2020-12-22 03:30:06 +01:00
## Gdk-pixbuf and gtk-doc installation
2020-12-22 03:30:06 +01:00
Download and untar.
2020-12-22 03:30:06 +01:00
$ wget https://download.gnome.org/sources/gdk-pixbuf/2.42/gdk-pixbuf-2.42.2.tar.xz
$ tar -Jxf gdk-pixbuf-2.42.2.tar.xz
$ wget https://download.gnome.org/sources/gtk-doc/1.33/gtk-doc-1.33.1.tar.xz
$ tar -Jxf gtk-doc-1.33.1.tar.xz
2020-12-22 03:30:06 +01:00
Same as before, install prerequisite packages, then compile and install them.
2020-12-22 03:30:06 +01:00
The installation of gtk-doc put `gtk-doc.pc` under `$HOME/local/share/pkgconfig`.
This file is used by pkg-config, which is one of the build tools.
The directory needs to be added to the environment variable `PKG_CONFIG_PATH`
2020-12-22 03:30:06 +01:00
$ export PKG_CONFIG_PATH="$HOME/local/share/pkgconfig:$PKG_CONFIG_PATH"
2020-12-22 03:30:06 +01:00
## Gtk4 installation
2020-12-22 03:30:06 +01:00
If you want the latest development version of gtk4, use git and clone the repository.
2020-12-22 03:30:06 +01:00
$ git clone https://gitlab.gnome.org/GNOME/gtk.git
2020-12-22 03:30:06 +01:00
If you want a stable version of gtk4, then download it from [Gnome source website](https://download.gnome.org/sources/gtk/4.0/).
2020-12-22 03:30:06 +01:00
Compile and install it.
2020-12-22 03:30:06 +01:00
$ meson --prefix $HOME/local _build
$ ninja -C _build
$ ninja -C _build install
2020-12-22 03:30:06 +01:00
2021-01-16 12:20:11 +01:00
If you want to know more information, refer to [Gtk4 reference manual](https://gnome.pages.gitlab.gnome.org/gtk/gtk/gtk-building.html).
## Modify env.sh
2020-12-22 03:30:06 +01:00
Because environment variables disappear when you log out, you need to add them again.
Modify `env.sh`.
2020-12-22 03:30:06 +01:00
# compiler
CPPFLAGS="-I$HOME/local/include"
LDFLAGS="-L$HOME/local/lib"
PKG_CONFIG_PATH="$HOME/local/lib/pkgconfig:$HOME/local/lib/x86_64-linux-gnu/pkgconfig:$HOME/local/share/pkgconfig"
export CPPFLAGS LDFLAGS PKG_CONFIG_PATH
# linker
LD_LIBRARY_PATH="$HOME/local/lib/x86_64-linux-gnu/"
PATH="$HOME/local/bin:$PATH"
export LD_LIBRARY_PATH PATH
# gir
XDG_DATA_DIRS=$HOME/local/share:$XDG_DATA_DIRS
export XDG_DATA_DIRS
# gsetting
export GSETTINGS_SCHEMA_DIR=$HOME/local/share/glib-2.0/schemas
# girepository-1.0
export GI_TYPELIB_PATH=$HOME/local/lib/x86_64-linux-gnu/girepository-1.0
2020-12-22 03:30:06 +01:00
Include this file by . (dot) command before using gtk4 libraries.
2020-12-22 03:30:06 +01:00
You may think you can add them in your `.profile`.
I think the environment variables above are necessary only when you compile gtk4 applications.
And it's not necessary except the case above and it might cause some bad things.
Therefore, I recommend you not to write them to your `.profile`.
2020-12-22 03:30:06 +01:00
## Compiling gtk4 applications
2020-12-22 03:30:06 +01:00
Before you compile gtk4 applications, define environment variables above.
$ . env.sh
After that you can compile them without anything.
For example, to compile `sample.c`, type the following.
$ gcc `pkg-config --cflags gtk4` sample.c `pkg-config --libs gtk4`
To know how to compile gtk4 applications, refer to the following sections.
2020-12-22 03:30:06 +01:00
2021-01-13 12:59:15 +01:00
Up: [Readme.md](../Readme.md), Prev: [Section 1](sec1.md), Next: [Section 3](sec3.md)