c - How do I use libdb-4.2 in a FreeBSD 9.1 system? -


i'm attempting write small program in c open , read berkeley 4.2 hash db on freebsd 9.1 system testing, can't compile. first time i've written in c , compiled command line i'm missing 1 thing that'll working, don't know.

after searching on , looking @ documentation , source code on github, i've got far:

#include <sys/types.h>  #include <stdio.h> #include <string.h> #include <stdlib.h>  #include <unistd.h>  #include <db.h>  int main() {                                                                    db * mydb;                                                                   u_int32_t open_flags = db_rdonly;   int ret;    ret = db_create(&mydb, null, 0);   if (ret != 0) {     printf("error creating db structure!");     return 1;   }    ret = mydb->open(mydb, null, "bsddb-py", null, db_hash, open_flags, 0);   if (ret != 0) {     printf("error opening db file!");     return 2;   }    mydb->close(mydb, 0); } 

i compile this:

cc -ldb-4.2 db_test.c 

and this:

db_test.c: in function 'main': db_test.c:20: error: 'db_rdonly' undeclared (first use in function) db_test.c:20: error: (each undeclared identifier reported once db_test.c:20: error: each function appears in.) db_test.c:29: error: 'db' has no member named 'open' db_test.c:35: error: many arguments function 'mydb->close' 

apparently compiler hung on using berkeley 1.85 (dbopen , such) , won't budge?

it looks #include <db.h> provide interface berkeley 1.85 because that's what's installed default on freebsd. have berkeley 4.2 installed via ports, , avoid conflicts, header interfaces 4.2 put elsewhere - referencing right library not right header.

so, changed include to:

#include <db42/db.h> 

...and compiled with...

cc -i/usr/local/include/ -l/usr/local/lib/ -ldb-4.2 db_test.c -o db_test 

running above source modification produced no visible output, means worked!

as newbie it, bsd weird.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -