Ticket #171 (closed task: invalid)

Opened 2 years ago

Last modified 1 year ago

Problem using rpm api's from a c program.

Reported by: vermadinkar Assigned to: FlorianFesti
Priority: major Milestone:
Component: rpm Version: RPM Development
Keywords: Cc:

Description

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

Change History

06/29/10 08:28:30 changed by vermadinkar

I wanted to inform that I am using rpm-5.1.9

(in reply to: ↑ description ) 06/29/10 08:29:15 changed by vermadinkar

Replying to vermadinkar:

== 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

I am using rpm-5.1.9

06/29/10 12:24:37 changed by FlorianFesti

  • owner changed from RpmTickets to FlorianFesti.
  • priority changed from blocker to major.

I am sorry, but this is not the right place for your issue. RPM5 is a fork that is separate from the RPM line of development for several years now although the naming might suggest something different. Please direct your questions to RPM5 project that can be found at http://rpm5.org if this is the platform you intend to develop for.

Florian Festi

10/06/10 07:15:25 changed by pmatilai

  • status changed from new to closed.
  • resolution set to invalid.