[ Solved ] DB->get: method not permitted before handle’s open method

Was writing a very simple program on BerkeleyDB as below

#include < db.h >

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

DB *dbp = NULL;

int ret = 0;

ret = db_create(&dbp, NULL, 0)

ret = dbp->open(dbp, NULL, “my_db.db”, NULL, DB_TREE, DB_CREATE, 0);

if (dbp != NUL ) {

    dbp->close(dbp, 0);

}

} /* end of main */

Compiled the program with following command

$ gcc -g -I/usr/local/BerkeleyDB.6.1/include -L/usr/local/BerkeleyDB.6.1/lib  test.c -ldb

When I executed the program , following error cropped up.

DB->get: method not permitted before handle’s open method

I was trying to use BerkeleyDB-6.1. But when I checked , to which library , the executable got linked to – I saw this.

             $ ldd a.out
               linux-vdso.so.1 =>  (0x00007ffff5dff000)
               libdb-4.7.so => /lib64/libdb-4.7.so (0x000000308ce00000)
               libc.so.6 => /lib64/libc.so.6 (0x0000003079600000)
               libpthread.so.0 => /lib64/libpthread.so.0 (0x000000307a200000)
               /lib64/ld-linux-x86-64.so.2 (0x0000003079200000)

As we can see , libdb-4.7 got linked with the executable. Then I realized , this is an error related to incorrect linking to different version of BerkeleyDB library on system. This may happen to systems ,  with multiple BerkeleyDB installed.

[ Solution ]

 1. First set up LD_LIBRARY_PATH  as bellow , before compiling the BerkeleyDB Program.

$ export LD_LIBRARY_PATH=/usr/local/BerkeleyDB.6.1/lib:$LD_LIBRARY_PATH

 2. Do compile the code from same shell

$ gcc -g -I/usr/local/BerkeleyDB.6.1/include -L/usr/local/BerkeleyDB.6.1/lib  test.c -ldb

3. Execute

The error will not crop up ever again. Hope this will be a direct help to someone. Cheers

😀

Advertisements

Simple , Artistic , Meaningful

Tagged with: , , , , , , , , , , , , , ,
Posted in computer, debug, troubleshoot

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: