一、Gtk4-安装ubuntu 20.04 or ubuntu 18.04

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

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

### 使用U盘将Ubuntu 18.04升级到Ubuntu 20.04的方法 在现有的Ubuntu 18.04系统上,通过U盘安装Ubuntu 20.04系统,可以按照以下方法进行操作。此过程涉及下载镜像文件、制作启动盘以及完成安装。 #### 、准备工作 1. **下载Ubuntu 20.04镜像文件** 访问Ubuntu官方网站,下载最新的Ubuntu 20.04桌面版ISO镜像文件[^2]。确保下载的文件完整且无损坏。 2. **准备U盘** 需要个容量至少为4GB的U盘,并确保其内容可以被清空。使用工具如Rufus(Windows下)或Etcher(Linux/Mac下)来制作启动盘[^2]。 3. **备份重要数据** 在升级过程中,可能会格式化硬盘分区或丢失数据。因此,建议提前备份所有重要文件。 #### 二、制作启动盘 1. **使用Rufus制作启动盘** 在Windows系统中,运行Rufus软件,插入U盘后选择已下载的Ubuntu 20.04 ISO文件。设置适当的参数(如文件系统选择“FAT32”),点击“开始”等待制作完成[^2]。 2. **验证启动盘** 制作完成后,建议在其他设备上测试启动盘是否正常工作,以避免后续安装失败。 #### 三、安装Ubuntu 20.04 1. **进入BIOS设置** 将制作好的U盘插入目标计算机,在开机时按下指定键(通常是F2、Del或Esc)进入BIOS设置界面。将U盘设置为第启动项[^1]。 2. **启动安装程序** 保存BIOS设置并重启计算机,从U盘启动进入Ubuntu 20.04安装界面。选择语言后,进入安装向导。 3. **选择安装方式** 在安装过程中,可以选择“升级现有Ubuntu版本”选项。此选项会保留用户的个人文件和配置,同时升级操作系统内核和软件包[^5]。 4. **完成安装** 按照屏幕提示完成剩余步骤,包括设置用户名、密码等。安装完成后,重启计算机并移除U盘。 #### 四、后续配置 1. **更新系统** 安装完成后,打开终端执行以下命令以确保系统最新: ```bash sudo apt update && sudo apt upgrade -y ``` 2. **安装显卡驱动** 如果需要安装NVIDIA显卡驱动,可以参考标准仓库自动安装方法或手动安装官方驱动[^3]。 3. **配置输入法** 如果需要使用中文输入法,可以卸载默认的ibus框架并安装fcitx框架及搜狗拼音输入法[^5]。 ```bash sudo apt-get remove ibus sudo apt-get purge ibus sudo apt-get remove indicator-keyboard sudo apt install fcitx-table-wbpy fcitx-config-gtk im-config -n fcitx ``` 4. **解决中文乱码问题** 如果出现中文乱码,可以通过安装字体包解决问题: ```bash sudo apt install fonts-wqy-zenhei ``` --- ###
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值