You are not logged in.
Hello there,
I wanted to start using db library. I've created the simple piece of code, everything based on a manpage:
#include <stdio.h>
#include <sys/types.h>
#include <limits.h>
#include <db.h>
int main() {
DB *base;
base = dbopen("db", O_CREAT, O_RDWR, DB_HASH, NULL);
if(!base)
printf("Failed to open database\n");
return 0;
}
They I tried compiling it. But then...
└─[%]─> gcc -Wall -pedantic test.c
test.c: In function 'main':
test.c:8: warning: implicit declaration of function 'dbopen'
test.c:8: error: 'O_CREAT' undeclared (first use in this function)
test.c:8: error: (Each undeclared identifier is reported only once
test.c:8: error: for each function it appears in.)
test.c:8: error: 'O_RDWR' undeclared (first use in this function)
test.c:8: warning: assignment makes pointer from integer without a cast
...suprise. Looks like I'm lacking some compiler flags, but I've found nothing like this in the manpage. Could you give me a hand?
Regards,
Ted
Offline
You need to include fcntl.h to get rid of the undeclared O_CREAT O_RDWR errors.
Offline
Thanks, but I still have the dbopen error
test.c: In function 'main':
test.c:9: warning: implicit declaration of function 'dbopen'
test.c:9: warning: assignment makes pointer from integer without a cast
/tmp/ccEfPHwW.o: In function `main':
test.c:(.text+0x31): undefined reference to `dbopen'
collect2: ld returned 1 exit status
Any ideas?
Regards
Offline
It seems that dbopen() is not a function from the db library. I don't see it in db.h header. Perhaps you can check that db tutorial: http://www.oracle.com/technology/docume … index.html.
Offline
If you're sure the function exists, try linking your program with the db library, like so:
gcc something.c -o something -ldb
Take this with a grain of salt, since I don't actually know anything about Berkeley DB.
Last edited by Peasantoid (2009-08-14 20:42:02)
Offline
I got it to work this way:
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <limits.h>
#include <db_185.h>
int main() {
DB *base;
base = dbopen("db", O_CREAT, O_RDWR, DB_HASH, NULL);
if(!base)
printf("Failed to open database\n");
return 0;
}
Compiler with -ldb
Seems like dbopen is a legacy function.
Offline