Solved

Error running the example code for Berkeley DB

Posted on 2004-10-29
4,279 Views
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"

int
main()
{
      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);
      else
            dbp->err(dbp, ret, "DB->get");

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

      exit(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???
0
Question by:kwseow
    2 Comments
     

    Author Comment

    by:kwseow
    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?
     
    0
     
    LVL 24

    Accepted Solution

    by:
    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.

    Regards
    Friedrich
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Introduction After workin in a plethora of programming languages like C, Pro*C, ESQL/C, C++, VC++, VB, Java, HTML,JavaScipt etc, technologies and frameworks like JSP, Servlets, Struts, Spring, IBatis etc and databases like MS Access, SQLServer, Inf…
    Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
    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…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    846 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now