一、Gtk4-安装ubuntu 20.04 or ubuntu 18.04

本文档详细介绍了在Ubuntu上手动编译安装GTK4的步骤,包括查看Glib和GTK版本,安装所需的库和依赖,解决编译过程中遇到的问题,如错误选项和版本不匹配等。此外,还提供了编译GTK4时的meson选项配置,并给出了测试安装成功的命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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’请添加图片描述

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

Ubuntu 20.04中,当在终端中输入`matlab`后,可能会出现`Failed to load module "canberra-gtk-module"`的错误信息。这是因为Ubuntu 18.04/20.04默认安装的是libcanberra-gtk3-module(gtk-3.0),而Matlab需要调用的是gtk-2.0的canberra动态链接库。尽管在gtk-3.0目录下也有gtk-2.0版本的动态链接库文件,但Matlab似乎不支持同路径下的多个版本的libcanberra-gtk-module.so文件。为了解决这个问题,你可以尝试以下方法: 1. 首先,确保你已经安装gtk-2.0的canberra动态链接库。你可以通过运行以下命令来安装它: ``` sudo apt-get install libcanberra-gtk-module:i386 ``` 2. 如果安装成功,你可以尝试在终端中再次输入`matlab`来启动Matlab,看看是否还会出现相同的错误信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Ubantu,Matlab Failed to load module ‘canberra-gtk-module](https://blog.csdn.net/qq_45535886/article/details/120281161)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [ubuntu18.04运行matlab2022b出现 Failed to load module “canberra-gtk-module](https://blog.csdn.net/cherish1211/article/details/130422466)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值