How to use libapt (or libept) in debian-like system to list packages and get their infos?

前端 未结 3 1692
春和景丽
春和景丽 2021-01-02 01:01

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

Libapt is not well-documented at all, and i\'ve found few

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-02 01:13

    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.

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

    How to list all packages:

    #include 
    #include 
    
    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;
    }
    

提交回复
热议问题