Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Error running the example code for Berkeley DB

Posted on 2004-10-29
Medium Priority
Last Modified: 2010-04-29
Hi there,

I've compiled succesfully the sample code for testing Berkeley DB as follow:

#include <sys/types.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "db.h"

#define      DATABASE "access.db"

      DB *dbp;
      DBT key, data;
      int ret, t_ret;
      /* Create the database handle and open the underlying database. */
      printf ("test 1");
      if ((ret = db_create(&dbp, NULL, 0)) != 0) {
            fprintf(stderr, "db_create: %s\n", db_strerror(ret));
            exit (1);
      printf("test 2");
      if ((ret = dbp->open(dbp,NULL, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
            dbp->err(dbp, ret, "%s", DATABASE);
            goto err;
      printf("test 3");
      /* Initialize key/data structures. */
      memset(&key, 0, sizeof(key));
      memset(&data, 0, sizeof(data));
      key.data = "fruit";
      key.size = sizeof("fruit");
      data.data = "apple";
      data.size = sizeof("apple");

      /* Store a key/data pair. */
      if ((ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
            printf("db: %s: key stored.\n", (char *)key.data);
      else {
            dbp->err(dbp, ret, "DB->put");
            goto err;

      /* Retrieve a key/data pair. */
      if ((ret = dbp->get(dbp, NULL, &key, &data, 0)) == 0)
            printf("db: %s: key retrieved: data was %s.\n",
                (char *)key.data, (char *)data.data);
      else {
            dbp->err(dbp, ret, "DB->get");
            goto err;

      /* Delete a key/data pair. */
      if ((ret = dbp->del(dbp, NULL, &key, 0)) == 0)
            printf("db: %s: key was deleted.\n", (char *)key.data);
      else {
            dbp->err(dbp, ret, "DB->del");
            goto err;

      /* Retrieve a key/data pair. */
      if ((ret = dbp->get(dbp, NULL, &key, &data, 0)) == 0)
            printf("db: %s: key retrieved: data was %s.\n",
                (char *)key.data, (char *)data.data);
            dbp->err(dbp, ret, "DB->get");

err:      if ((t_ret = dbp->close(dbp, 0)) != 0 && ret == 0)
            ret = t_ret;


However, I get an error :

error while loading shared libraries: libdb-4.2.so: cannot open shared object file: No such file or directory

However, the libdb-4.2.so file is found in /usr/local/BerkeleyDB4.2/lib

I've also included   /usr/local/BerkeleyDB4.2/include in the include path and  /usr/local/BerkeleyDB4.2/lib in the library path.

Any idea what's wrong???
Question by:kwseow
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Author Comment

ID: 12445976
Guess I found the answer... just ln this .so file into /usr/lib

However, do I need to link libdb.so and libdb.so.2 to /usr/local/Berkeley.4.2/lib/libdb-4.2.so as well? Currently, both are linked to libdb-4.0.so

And what could be the possible effect of changing this?
LVL 24

Accepted Solution

fridom earned 2000 total points
ID: 12474917
You have to include the path to the library e.g into ld.so.conf, don't forget to run ldconfig after adding it.

Or use the environement variable LD_LIBRARY_PATH or do make symbolic link from directories which are searched e.g /usr/lib
If the libraries are symbolic links then you have to check if the files the point to are exitent. If not you can unlink and relink them.

Or you may want to install Berkeley DB from your Linux installation media or Server.


Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question