LinuxQuestions.org
Help answer threads with 0 replies.
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 11-13-2006, 02:19 AM   #1
bruce_goose
LQ Newbie
 
Registered: Nov 2006
Posts: 4

Rep: Reputation: 0
Unable to get dbopen to work in C.


Hi All,

I am using RedHat Linux 2.6.9-1.667smp on a standard intel desktop and I've written a simple little test program to prove that dbopen works and I just
can't get it to compile properly. I really need help with this one as I'm stuck.

The error message I get is as follows,

cc -g -I/usr/include -c dbtest.c -o dbtest.o
dbtest.c: In function `main':
dbtest.c:14: error: `RECNOINFO' undeclared (first use in this function)
dbtest.c:14: error: (Each undeclared identifier is reported only once
dbtest.c:14: error: for each function it appears in.)
dbtest.c:14: error: syntax error before "rec"
dbtest.c:17: error: `rec' undeclared (first use in this function)
dbtest.c:17: error: `R_FIXEDLEN' undeclared (first use in this function)
dbtest.c:26: warning: assignment makes pointer from integer without a cast
cons: *** [dbtest.o] Error 1
cons: errors constructing dbtest.o




the program is as follows.
------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <limits.h>
#include <db.h>

main()
{
DB *ptr;
RECNOINFO rec;
char *fname="test.dat";

rec.flags = R_FIXEDLEN;
rec.cachesize=0; /* use default cachesize */
rec.psize = 0; /* Let system select page size. */
rec.lorder = 0; /* Use current Host ordering. */
rec.reclen = 20;/* 20 byte record length */
rec.bval = '\0';/* Padding char used when fixed length. */
rec.bfname= NULL; /* Don't need to know about internal b-tree. */

ptr = dbopen( fname,(int) O_CREAT|O_EXCL|O_RDWR,(int) S_IWRITE|S_IREAD,
DB_RECNO, (const void *) &rec );
}
 
Old 11-13-2006, 03:48 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,288

Rep: Reputation: 174Reputation: 174
shouldn't that be
#include <dbm.h> ?

(or maybe ndbm.h )

Last edited by bigearsbilly; 11-13-2006 at 04:01 AM.
 
Old 11-13-2006, 04:04 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,288

Rep: Reputation: 174Reputation: 174
Quote:
shouldn't that be
#include <dbm.h> ?

(or maybe ndbm.h )
and also shouldn't that be:
DBM *ptr;
 
Old 11-15-2006, 06:28 AM   #4
bruce_goose
LQ Newbie
 
Registered: Nov 2006
Posts: 4

Original Poster
Rep: Reputation: 0
Hi Billy,

the dbm libraries appear to be part of the GNU db libraries rather than the db libraries. All the examples I have found on the internet for dbopen indicate that I should be using <db.h> and setting my pointer as a DB *ptr.

I have found references to RECNOINFO and the other missing defintions in db_185.h - but I don't know what that is or whether I should be using it.

Grrr.... frustration reigns at the moment...

Bruce.
 
Old 11-15-2006, 09:36 PM   #5
bruce_goose
LQ Newbie
 
Registered: Nov 2006
Posts: 4

Original Poster
Rep: Reputation: 0
OK - I've worked out what to do.

#include <db.h>
has to become
#include <db_185.h>

(which is - unfortunately different to every example I have found on the net).

and the compilation phase also needs to include the db library
ie,

cc -g -ldb -I/usr/include -c dbtest.c -o dbtest.o

Thanks folks - you're help was appreciated Billy.

Bruce.
 
Old 03-23-2007, 07:52 PM   #6
dave570
LQ Newbie
 
Registered: Mar 2007
Posts: 1

Rep: Reputation: 0
db_185.h

I believe when Berkeley DB is built it automaticaly includes db-1.8.5
compatability. So u must be using BerkeleyDB version 2 or higher. Their
file formats change as often as their underware. If u build DB yourself u
can use a command line switch in the configure file to shut it off. So if u
write any code using db-1,8,5 calls u must include db_185.h. I'm sure if
i'm wrong someone on here will let me know.
 
  


Reply

Tags
programming


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Unable to get partitioning tool to work jerrynewt Linux - Desktop 11 11-12-2006 03:42 PM
Squid: Unable to get SSL to work deadlock1981 Linux - Networking 1 09-10-2006 01:55 PM
work but unable to connect 5n1p3r Linux - Wireless Networking 1 08-08-2006 08:12 AM
Unable to get WMP11v27 to work with ndiswrapper gad241 Linux - Wireless Networking 2 04-18-2006 04:59 PM
Unable to get Real Player to work (please help!) LaptopLinux Linux - Software 1 06-30-2005 10:36 PM


All times are GMT -5. The time now is 10:05 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration