I tried to execute the following code.
*****************************************************
#include <errno.h>
#include<sys/time.h>
#include<stdint.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <rpmiotypes.h>
#include <rpmlib.h>
int main(int argc, char ** argv) {
rpmdb * pdb;
rpmReadConfigFiles(NULL, NULL);
printf("Config files read\n");
int dbStatus = rpmdbOpen("", &pdb, O_RDONLY, 0644);
if (dbStatus) {
// error opening
printf("Error on opening RPM Database: (%d) %s\n", rpmErrorCode(), rpmErrorString());
exit;
} else {
printf("RPM Database opened!\n");
}
rpmdbMatchIterator mi = rpmdbInitIterator(pdb, RPMDBI_PACKAGES, NULL, 0);
printf("Iterator initialized!\n");
Header header;
HeaderIterator? hi;
uint32_t type, count;
char * name;
while (header = rpmdbNextIterator(mi)) {
headerGetEntry(header, RPMTAG_NAME, &type, (void **) &name, &count);
printf("%s\n", strdup(name));
}
printf("Finished Iteration!\n");
rpmdbFreeIterator(mi);
printf("Iterator Finished!\n");
rpmdbClose(pdb);
printf("RPM Database closed!\n");
}
******************************************************************************
While compiling I get the following errors.
sample_rpm.c: In function 'main':
sample_rpm.c:31: warning: initialization makes pointer from integer without a cast
sample_rpm.c:38: warning: assignment makes pointer from integer without a cast
/tmp/cccmT5r5.o: In function `main':
sample_rpm.c:(.text+0x53): undefined reference to `rpmErrorString'
sample_rpm.c:(.text+0x5a): undefined reference to `rpmErrorCode'
sample_rpm.c:(.text+0xc1): undefined reference to `headerGetEntry'
collect2: ld returned 1 exit status
While going through the online documentation I found that function 'headerGetEntry' is defined in the file hdrinline.h and some changes have also been done related to the header related api's. I tried including that but still got the same error along with some more.
Can somebody help me out with the problem and how to fix it.
It would be great if someone can also provide some link regarding how to use the api's from a C program.
Thanks
Dinkar Verma