LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-19-2004, 03:41 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
Question 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.

Last edited by eantoranz; 01-19-2004 at 03:42 PM.
 
Old 01-19-2004, 04:07 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
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.
 
Old 01-19-2004, 04:20 PM   #3
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
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! :'(

Last edited by eantoranz; 01-20-2004 at 01:00 PM.
 
Old 01-20-2004, 11:09 PM   #4
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
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
 
Old 01-21-2004, 12:19 AM   #5
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
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!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined reference, why? george_mercury Programming 4 05-07-2009 12:15 AM
Undefined Reference ChemicalBurn Programming 2 02-14-2005 03:01 AM
undefined reference mp4-10 Programming 3 01-25-2005 12:38 PM
undefined reference to 'gdbm_open' Castro Linux - Newbie 1 06-11-2003 03:13 PM
Yet another 'undefined reference' problem faulpelz2 Linux - Software 3 04-04-2003 11:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration