通过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 文件的每一步执行情况

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

相关推荐
likfishdn几秒前
Linux的文件与目录管理
linux·运维·服务器
chian-ocean20 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=21 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
追寻光1 小时前
Cannot find a valid baseurl for repo: base/7/x86_64
linux
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
陆沙1 小时前
deepseek-r1-centos-本地服务器配置方法
linux·服务器·centos
吃汤圆的抹香鲸1 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net
sz66cm2 小时前
Linux基础 -- ARM 32 位架构动态注入代码技术文档
linux·arm开发·架构
Mr.pyZhang4 小时前
Android构建系统 - 04 编译产物
android·linux