通过packageKit完成的系统更新(一)

最近在学习packagekit,学习是如何进行的系统更新,本系列主要讲述,如何使用packageKit接口实现系统更新。

  1. 导入依赖

在使用packageKit 之前需要导入一些依赖和安装一些包,不然会报错,以下以报错信息讲解:

复制代码
cmakelist demo/updatesystemdemo/mainwindow.cpp:9: error: PackageKit/Daemon: No such file or directory
demo/updatesystemdemo/mainwindow.cpp:9:10: fatal error: PackageKit/Daemon: No such file or directory
    9 | #include <PackageKit/Daemon>
      |          ^~~~~~~~~~~~~~~~~~~

上面的问题 即是直接在代码中引入头文件报错的信息,下面是解决方案:

这个错误表明编译器在尝试编译程序时找不到 `PackageKit/Daemon` 头文件。这通常是因为以下几个原因:

  1. PackageKit未安装:在系统上可能没有安装PackageKit的开发包,执行以下命令安装:
cpp 复制代码
sudo apt-get update
sudo apt-get install libpackagekit-glib2-dev 
sudo apt-get install packagekit-glib2-dev
  1. 安装完成后,还需要在cmakelist中添加相应语句:

    cmake_minimum_required(VERSION 3.0)
    project(UpdateSystemDemo)

    找到PackageKit

    find_package(PackageKit REQUIRED)

    包含PackageKit头文件

    include_directories(${PACKAGEKIT_INCLUDE_DIRS})

    add_executable(UpdateSystemDemo mainwindow.cpp)

    链接PackageKit库

    target_link_libraries(UpdateSystemDemo ${PACKAGEKIT_LIBRARIES})

  2. 以上步骤执行完后,会报错信息如下:

cpp 复制代码
/demo/updatesystemdemo/CMakeLists.txt:17:
 error: By not providing "FindPackageKit.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "PackageKit", but CMake did not find one. Could not find a package configuration file provided by "PackageKit" with any of the following names: PackageKitConfig.cmake packagekit-config.cmake Add the installation prefix of "PackageKit" to CMAKE_PREFIX_PATH or set "PackageKit_DIR" to a directory containing one of the above files.  If "PackageKit" provides a separate development package or SDK, be sure it has been installed.

这个错误信息表明 CMake 在尝试定位 PackageKit 库时失败了。CMake 可以通过两种方式来寻找依赖项:使用 `Find<PackageName>.cmake` 模块或者使用 `<PackageName>Config.cmake` 配置文件。在此情况下,它正在寻找 `PackageKitConfig.cmake` 或 `packagekit-config.cmake` 文件,但是没有找到。

可以指定文件目录:

cpp 复制代码
include_directories(/usr/include/packagekitqt5)
  1. 接下来又有新的报错:
cpp 复制代码
/demo/updatesystemdemo/CMakeLists.txt:22: error: Found package configuration file: /usr/lib/x86_64-linux-gnu/cmake/packagekitqt5/packagekitqt5-config.cmake but it set PackageKitQt5_FOUND to FALSE so package "PackageKitQt5" is considered to be NOT FOUND.

这个错误,就可以看对应文件的.cmake文件,看具体是哪里设置为了false,基本都是缺少依赖的包,我这里缺少的是qt5dbus,直接安装就可以了。

cpp 复制代码
sudo apt-get install libqt5dbus5 qttools5-dev qttools5-dev-tools

讲一个小技巧,对于这种cmake文件,具体想看他执行到哪一步,可以使用下面的命令:

cpp 复制代码
cmake --trace-source="packagekitqt5-config.cmake" ..
这将打印出 packagekitqt5-config.cmake 文件的每一步执行情况

此篇讲解完了,如何安装依赖文件,引入库,下一篇讲述,如何获取系统是否需要更新。

相关推荐
luck_me523 分钟前
k8s v1.26 实战csi-nfs 部署
linux·docker·云原生·容器·kubernetes
不摆烂选手24 分钟前
Linux 阻塞和非阻塞 I/O 简明指南
linux·驱动开发·ubuntu·正点原子imx6ull学习笔记
SweerItTer1 小时前
由镜像源配置错误导致的软件包依赖问题
linux·vscode·ubuntu
kedvellek1 小时前
Linux 内核链表宏的详细解释
linux·运维·链表
chennalC#c.h.JA Ptho2 小时前
lubuntu 系统详解
linux·经验分享·笔记·系统架构·系统安全
冼紫菜2 小时前
解决 CentOS 7 镜像源无法访问的问题
linux·运维·服务器·centos
几道之旅2 小时前
分别在windows和linux上使用curl,有啥区别?
linux·运维·windows
季柳东2 小时前
在虚拟机Ubuntu18.04中安装NS2教程及应用
linux·运维·ubuntu
冼紫菜2 小时前
如何在 CentOS 7 虚拟机上配置静态 IP 地址并保持重启后 SSH 连接
linux·开发语言·centos·ssh
oioihoii2 小时前
C++23 views::slide (P2442R1) 深入解析
linux·算法·c++23