You are not logged in.
Pages: 1
Hi all!
I download the pacman tarball and try to use it in a simple program, only for test.
The program looks like:
#include <alpm.h>
main(){
alpm_init()
alpm_del()
}
The problem is that isn't compile. It's say something about yo use "__atribute__" in the headers files, more specific about the return type of functions.
I try to use -fvisibility=(default|hidden|internal) but it's doesn't work. I also try to use #pragma GCC visibility push(default) bout the same result.
How can I use this lib?
Offline
Here is a little example taken from another thread :
http://bbs.archlinux.org/viewtopic.php? … 77#p275277
/*
* displaypkg.c : Display the locally installed packages sorted by size.
*
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <alpm.h>
#include <alpm_list.h>
int pkg_cmp(const void *v1, const void *v2)
{
pmpkg_t *p1 = (pmpkg_t *)v1;
pmpkg_t *p2 = (pmpkg_t *)v2;
unsigned long int s1 = alpm_pkg_get_size(p1);
unsigned long int s2 = alpm_pkg_get_size(p2);
return(s2 - s1);
}
int main(int argc, char **argv)
{
pmdb_t *db = NULL;
alpm_list_t *i;
if(alpm_initialize() == -1) {
fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(pm_errno));
exit(EXIT_FAILURE);
}
/* let us get log messages from libalpm */
alpm_option_set_dbpath("/var/lib/pacman");
db = alpm_db_register_local();
if(db == NULL) {
fprintf(stderr, "error: could not register 'local' database (%s)\n",
alpm_strerror(pm_errno));
exit(EXIT_FAILURE);
}
alpm_list_t *list = alpm_db_getpkgcache(db);
list = alpm_list_msort(list, alpm_list_count(list), pkg_cmp);
for(i = list; i; i = alpm_list_next(i)) {
pmpkg_t *pkg = alpm_list_getdata(i);
printf("%s %lu\n", alpm_pkg_get_name(pkg), alpm_pkg_get_size(pkg)/1024);
}
if(alpm_release() == -1) {
fprintf(stderr, "error releasing alpm: %s\n", alpm_strerror(pm_errno));
}
exit(EXIT_SUCCESS);
}
compile :
$ gcc displaypkg.c -o displaypkg -lalpm -Wall
run :
$ ./displaypkg | column -t
There are also three other similar little tools in src/util : testdb, testpkg and vercmp.
Last edited by shining (2008-01-22 13:18:12)
pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))
Offline
Cul!!!
Very Thanks!!
Offline
Pages: 1