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

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

相关推荐
用户8055336980317 小时前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户8055336980317 小时前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
七歌杜金房1 天前
我终于又有了自己的 Linux 电脑
linux·debian·mac
tntxia2 天前
linux curl命令详解_curl详解
linux
扛枪的书生2 天前
Linux 网络管理器用法速查
linux
顺风尿一寸2 天前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
XIAOHEZIcode3 天前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
唐青枫3 天前
别再只会用 cron:Linux systemd Timer 定时任务实战详解
linux
AlfredZhao5 天前
生产环境里,为什么不建议把普通端口直接暴露到公网?
linux·https·443·80
戴为沐6 天前
Linux内存扩容指南
linux