LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   undefined reference to `rpmdbFirstRecNum' (https://www.linuxquestions.org/questions/programming-9/undefined-reference-to-%60rpmdbfirstrecnum-136460/)

eantoranz 01-19-2004 03:41 PM

undefined reference to `rpmdbFirstRecNum'
 
Guys.... I'm learning (trying to learn) the rpm-devel api. I'm compiling a veeeery simple program I made to traverse the rpm database. When I compile I get this error messages:

[antoranz@galileo src]$ gcc rpm4.c -o rpm4 -lrpm
rpm4.c: In function `main':
rpm4.c:32: warning: assignment makes pointer from integer without a cast
/home/antoranz/tmp/cctmhgcw.o(.text+0x91): In function `main':
: undefined reference to `rpmdbFirstRecNum'
/home/antoranz/tmp/cctmhgcw.o(.text+0xad): In function `main':
: undefined reference to `rpmdbGetRecord'
/home/antoranz/tmp/cctmhgcw.o(.text+0xc1): In function `main':
: undefined reference to `rpmdbGetNextRecNum'
collect2: ld returned 1 exit status

I can open de RPM Database with rpmdbOpen()... made an even simpler program and it was successful... however when I try to traverse the DB, you can see the functions needed fail. :(

What do I have to do?

Here you can see the follow up.
http://www.linuxquestions.org/questi...hreadid=135881
I decided to make another thread because this is a little more specific than the other thread I started before.

jim mcnamara 01-19-2004 04:07 PM

The missing references mean that you are not linking in the correct libraries.

On line 32, you'd need to post your code to decide what the actual error is.

eantoranz 01-19-2004 04:20 PM

this is the whole code:

#include <fcntl.h>

#include <rpm/rpmlib.h>

int main(int argc, char ** argv) {

rpmdb * pdb;

//rpmReadConfigFiles(NULL, NULL, NULL, 0); deprecated
// int rpmReadConfigFiles(/*@null@*/ const char * file, /*@null@*/ const char * target)
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());
} else {
printf("RPM Database opened!\n");
}

/* will try to get all the packages installed in the DB */

int offset;

offset = rpmdbFirstRecNum(pdb);
Header rpmHeader;

while (offset) {
rpmHeader = rpmdbGetRecord(pdb, offset);

offset = rpmdbGetNextRecNum(pdb, offset);
}

rpmdbClose(pdb);
printf("RPM Database closed!\n");
}

This is the output when compiling:
[antoranz@galileo src]$ gcc rpm4.c -o rpm4 -lrpm
rpm4.c: In function `main':
rpm4.c:31: warning: assignment makes pointer from integer without a cast
/home/antoranz/tmp/ccBAY42k.o(.text+0x91): In function `main':
: undefined reference to `rpmdbFirstRecNum'
/home/antoranz/tmp/ccBAY42k.o(.text+0xad): In function `main':
: undefined reference to `rpmdbGetRecord'
/home/antoranz/tmp/ccBAY42k.o(.text+0xc1): In function `main':
: undefined reference to `rpmdbGetNextRecNum'
collect2: ld returned 1 exit status

PS I justified the source, but it's not showing up. :(
PS2 Come on, guys! Help me! :'(

eantoranz 01-20-2004 11:09 PM

Guys.. I just founf out that the RPM API apapently doesn't support rpmdbFirstRecNum, rpmdbGetRecord, rpmdbGetNextErcNum since RPM 4.0 .... but one has to implement Iterators instead. Take a look here:
http://www.rpm.org/rpmapi-4.1/group__rpmdb.html#a18

eantoranz 01-21-2004 12:19 AM

After having spent some hours moving back and forth... here is the code:

#include <fcntl.h>

#include <rpm/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;

int_32 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");
}

Now I have to figure out what I did. ;)

Have fun!


All times are GMT -5. The time now is 11:01 AM.