如何在类似 debian 的系统中使用 libapt(或 libept)来列出软件包并获取它们的信息? [英] How to use libapt (or libept) in debian-like system to list packages and get their infos?

查看:20
本文介绍了如何在类似 debian 的系统中使用 libapt(或 libept)来列出软件包并获取它们的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人在类似 debian 的系统中使用 libapt 或 libept 列出软件包并获取有关软件包的信息吗?

Somebody used libapt or libept to list packages and get informations about package in a debian-like system?

Libapt 根本没有很好的文档记录,我发现很少有关于 libept 的示例和教程.有人可以向我解释最好的方法吗

Libapt is not well-documented at all, and i've found few examples and tutorials about libept. Can someone explain me best methods to

  1. 获取 apt-system 中每个包的列表
  2. 获取有关单个包的信息(如名称、版本、依赖项、描述等.
  3. 获取单个包安装的文件列表

直接使用 apt 内部文件非常简单,但我想使用一个库来遵守 apt 规范.

Work directly with apt internal files is quite simple, but i want to use a library to respect apt specifications.

推荐答案

在 debian 中有一个名为 libapt-pkg-doc 的包,其中包含一些文档(如 API 参考).安装后,您可以通过 file:///usr/share/doc/libapt-pkg-doc/html/index.xhtml 访问它.

In debian there is a package called libapt-pkg-doc which contains some documentation (like an API reference). Once installed, you can access it at file:///usr/share/doc/libapt-pkg-doc/html/index.xhtml.

我只看过 libapt,这是我目前学到的东西:

I only just had a look at libapt and here is what I have learned so far:

如何列出所有包:

#include <apt-pkg/cachefile.h>
#include <apt-pkg/pkgcache.h>

int main() {
    // _config and _system are defined in the libapt header files
    pkgInitConfig(*_config);
    pkgInitSystem(*_config, _system);

    pkgCacheFile cache_file;
    pkgCache* cache = cache_file.GetPkgCache();

    for (pkgCache::PkgIterator package = cache->PkgBegin(); !package.end(); package++) {
        std::cout << package.Name() << std::endl;
    }

    return 0;
}

这篇关于如何在类似 debian 的系统中使用 libapt(或 libept)来列出软件包并获取它们的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆