1 如何查看Glib库版本
gedit /usr/lib/aarch64-linux-gnu/glib-2.0/include/glibconfig.h
查看以下几个宏 version = 2.68.3
#define GLIB_MAJOR_VERSION 2
#define GLIB_MINOR_VERSION 68
#define GLIB_MICRO_VERSION 3
2 如何查看GTK-4版本
# usr/include 下搜索 gtkversion.h
#define GTK_MAJOR_VERSION (4)
/**
* GTK_MINOR_VERSION:
*
* Like [func@get_minor_version], but from the headers used at
* application compile time, rather than from the library linked
* against at application run time.
*/
#define GTK_MINOR_VERSION (8)
/**
* GTK_MICRO_VERSION:
*
* Like [func@get_micro_version], but from the headers used at
* application compile time, rather than from the library linked
* against at application run time.
*/
#define GTK_MICRO_VERSION (1)
3 GTK4安装
因为meson默认编译安装路径是/usr/local/,该路径不在标准库搜索路径下,所以选择安装在 /usr 路径下。
sudo apt-get -y install libncurses5
sudo apt-get -y install libelf++0 libelf1 libelf-dev
sudo apt-get -y install libxml2 libxml2-dev libxml2-utils
sudo apt-get -y install libxslt1-dev libxslt1.1
sudo apt-get -y install sysprof libpango1.0-dev
sudo apt-get -y install libpango-1.0-0 libpangocairo-1.0-0
sudo apt-get -y install libglib2.0-0 libglib2.0-dev
sudo apt-get -y install libxkbcommon-dev libxrandr-dev libxrender-dev
sudo apt-get -y install libxi-dev libxdamage-dev libxfixes-dev
sudo apt-get -y install libxext-dev libxcursor-dev libfontconfig-dev
sudo apt-get -y install libx11-dev libwayland-dev libpng-dev
sudo apt-get -y install libc6-dev libc6 libc6-amd64 libc++-10-dev
sudo apt-get -y install libc++-dev
sudo apt-get -y install libpng++-dev libpng-dev libpng16-16
sudo apt-get -y install libjpeg-dev libjpeg62 libjpeg8 libjpeg8-dev
sudo apt-get -y install libspectre-dev libspectre1
sudo apt-get -y install librsvg2-2 librsvg2-dev
sudo apt-get -y install libpixman-1-0 libpixman-1-dev
sudo apt-get -y install libxcb-shm0 libxcb-shm0-dev
sudo apt-get -y install cairo-5c
sudo apt-get -y install libicu-dev libthai-dev
sudo apt-get -y install libvulkan-dev libvulkan1
sudo apt-get -y install libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-dev
sudo apt-get update
sudo apt-get -y install libegl1-mesa libegl1-mesa-dev
sudo apt-get -y install libgles2-mesa-dev libglfw3-dev libglfw3
sudo apt-get -y install libglew-dev libglew2.1
sudo apt-get -y install ffmpeg libatk1.0-dev libglm-dev iso-codes
sudo apt-get -y install libgraphene-1.0-dev libgraphene-1.0-0
sudo apt-get -y install sassc hicolor-icon-theme libglib2.0-0
sudo apt-get -y install libglib2.0-dev pkg-config bison gettext
sudo apt-get -y install xsltproc
sudo apt-get -y install libpython3.9 --fix-missing
sudo apt-get -y install python3.9-full
sudo apt-get -y install python3.9-dev
sudo wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
sudo python3 get-pip.py -i https://pypi.mirrors.ustc.edu.cn/simple/
sudo python3 -m pip install --upgrade pip -i https://pypi.mirrors.ustc.edu.cn/simple/
sudo python3 -m pip install --upgrade setuptools -i https://pypi.mirrors.ustc.edu.cn/simple/
sudo python3 -m pip install --upgrade wheel -i https://pypi.mirrors.ustc.edu.cn/simple/
sudo python3 -m pip install meson -i https://pypi.mirrors.ustc.edu.cn/simple/
sudo python3 -m pip install ninja -i https://pypi.mirrors.ustc.edu.cn/simple/
sudo python3 -m pip install cmake -i https://pypi.mirrors.ustc.edu.cn/simple/
sudo mkdir build
sudo mkdir build/glib2
sudo git clone https://github.com/GNOME/glib.git build/glib2
# 最好安装 2.73.5以后的版本 G_Application有个宏FLag变化
sudo git --work-tree=build/glib2 --git-dir=build/glib2/.git checkout tags/2.75.1 -b 2.75.1
sudo mkdir build/glib2/_build
sudo meson -Dprefix=/usr -Dtests=false build/glib2/_build build/glib2
sudo ninja -C build/glib2/_build -j 1
sudo ninja -C build/glib2/_build install
sudo mkdir build/pango
sudo git clone https://github.com/GNOME/pango.git build/pango
sudo git --work-tree=build/pango --git-dir=build/pango/.git checkout tags/1.50.12 -b 1.50.12
sudo mkdir build/pango/_build
sudo meson -Dprefix=/usr -Dgtk_doc=false build/pango/_build build/pango
sudo ninja -C build/pango/_build -j 1
sudo ninja -C build/pango/_build install
sudo mkdir build/vulkan
sudo git clone https://github.com/KhronosGroup/Vulkan-Headers.git build/vulkan
sudo git --work-tree=build/vulkan --git-dir=build/vulkan/.git checkout tags/v1.2.179 -b v1.2.179
sudo mkdir build/vulkan/_build
sudo cmake build/vulkan -B build/vulkan/_build -DCMAKE_INSTALL_PREFIX=/usr
sudo cmake --build build/vulkan/_build --target install
sudo rm -fr build/vulkan
sudo mkdir build/vulkan
sudo git clone https://github.com/KhronosGroup/Vulkan-Loader.git build/vulkan
sudo git --work-tree=build/vulkan --git-dir=build/vulkan/.git checkout tags/v1.2.179 -b v1.2.179
sudo mkdir build/vulkan/_build
sudo cmake build/vulkan -B build/vulkan/_build -DCMAKE_INSTALL_PREFIX=/usr
sudo cmake --build build/vulkan/_build --target install
sudo mkdir build/gtk4
sudo git clone https://github.com/GNOME/gtk.git build/gtk4
sudo git --work-tree=build/gtk4 --git-dir=build/gtk4/.git checkout tags/4.8.1 -b 4.8.1
sudo mkdir build/gtk4/_build
sudo meson -Dprefix=/usr build/gtk4/_build build/gtk4
sudo ninja -C build/gtk4/_build -j 1
sudo ninja -C build/gtk4/_build install
关于编译Gtk4的一些meson选项,可以在meson_options.txt文档中进行设置
后面章节要使用drafting,broadway-backend=true
# GDK backends
option('x11-backend',
type: 'boolean',
value: true,
description : 'Enable the X11 gdk backend (only when building on Unix)')
option('wayland-backend',
type: 'boolean',
value: true,
description : 'Enable the wayland gdk backend (only when building on Unix except for macOS)')
option('broadway-backend',
type: 'boolean',
value: true,
description : 'Enable the broadway (HTML5) gdk backend')
option('win32-backend',
type: 'boolean',
value: true,
description : 'Enable the Windows gdk backend (only when building on Windows)')
option('macos-backend',
type: 'boolean',
value: true,
description : 'Enable the macOS gdk backend (only when building on macOS)')
# Media backends
# For distros: GTK guarantees support for WebM video (VP8 and VP9), so a supported build
# should provide that.
option('media-ffmpeg',
type: 'feature',
value: 'disable',
description : 'Build the experimental ffmpeg media backend')
option('media-gstreamer',
type: 'feature',
value: 'enabled',
description : 'Build the gstreamer media backend')
# Print backends
option('print-cups',
type: 'feature',
value: 'auto',
description : 'Build the cups print backend')
# Optional features
option('vulkan',
type: 'feature',
value: 'auto',
description : 'Enable support for the experimental Vulkan renderer')
option('cloudproviders',
type: 'feature',
value: 'disabled',
description : 'Enable the cloudproviders support')
option('sysprof',
type: 'feature',
value: 'disabled',
description : 'include tracing support for sysprof')
option('tracker',
type: 'feature',
value: 'disabled',
description : 'Enable Tracker3 filechooser search')
option('colord',
type: 'feature',
value: 'disabled',
description : 'Build colord support for the CUPS printing backend')
option('f16c',
type: 'feature',
value: 'enabled',
description: 'Enable F16C fast paths (requires F16C)')
# Documentation and introspection
option('gtk_doc',
type: 'boolean',
value: false,
description : 'Build API reference and tools documentation')
option('update_screenshots',
type: 'boolean',
value: false,
description : 'Regenerate screenshots for the documentation')
option('man-pages',
type: 'boolean',
value: false,
description : 'Build man pages for installed tools')
option('introspection',
type: 'feature',
value: 'auto',
yield: true,
description : 'Build introspection data (requires gobject-introspection)')
# Demos, examples and tests
option('demos',
type: 'boolean',
value: true,
description : 'Build demo programs')
option('profile',
type: 'combo',
choices: [ 'default', 'devel' ],
value: 'default',
description : 'Profile to use for demos')
option('build-examples',
type: 'boolean',
value: true,
description : 'Build examples')
option('build-tests',
type: 'boolean',
value: true,
description : 'Build tests')
option('install-tests',
type: 'boolean',
value: false,
description : 'Install tests')
3 测试安装成功
pkg-config --cflags gtk4
pthread -I/usr/include/gtk-4.0 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/harfbuzz -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/graphene-1.0 -I/usr/lib/aarch64-linux-gnu/graphene-1.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include
4 错误
4.1 ERROR: Unknown options: “media, print-backends”
删除 media 和 print-backends 选项
sudo meson -Dprefix=/usr -Dvulkan=enabled -Dwayland-backend=false -Dbroadway-backend=false -Dman-pages=false -Dgtk_doc=false -Ddemos=false -Dbuild-examples=false -Dbuild-tests=false -Dinstall-tests=false build/gtk-4.8.1/_build build/gtk-4.8.1
4.2 Dependency pango found: NO found 1.48.7 but need: ‘>= 1.50.0’![请添加图片描述](https://img-blog.csdnimg.cn/03fc7630bc3342e3b8c05bc8b2e3817d.png)
wget https://github.com/GNOME/pango/archive/refs/tags/1.50.10.zip
meson -Dprefix=/usr _build
cd _build
sudo ninja
sudo ninja install
4.3 harbuzz版本问题
未定义的函数在2.6.8版本中新增,系统是2.6.4版本,需要升级一下harfbuzz
https://github.com/harfbuzz/harfbuzz/releases
meson -Dprefix=/usr _build
cd _build
sudo ninja
sudo ninja install
-Dprefix=/usr
一定主要按照头文件、库的地址
参考1:Compile/Install GTK4 on Ubuntu Focal 20.04 or Bionic 18.04
参考2:Ubuntu20.04LTS(amd64/x86_64) 下安装 GTK4