Loading Berkeley DB with Tcl

This document assumes that you already configured Berkeley DB for Tcl support, and you have built and installed everything where you want it to be. If you have not done so, see or Building the Tcl API in the Berkeley DB Installation and Build Guide for more information.

Once enabled, the Berkeley DB shared library for Tcl is automatically installed as part of the standard installation process. However, if you want to be able to dynamically load it as a Tcl package into your script, there are several steps that must be performed:

  1. Append this directory to your auto_path variable.

Note that your Tcl and Berkeley DB version numbers may differ from the example, and so your tclsh and library names may be different.

Loading Berkeley DB with Tcl

The Berkeley DB package may be loaded into the user’s interactive Tcl script (or wish session) via the load command. For example:

If you installed your library to run as a Tcl package, Tcl application scripts should use the package command to indicate to the Tcl interpreter that it needs the Berkeley DB package and where to find it. For example:

No matter which way the library gets loaded, it creates a command named berkdb. All the Berkeley DB functionality is accessed via this command and additional commands it creates on behalf of the application. A simple test to determine whether everything is loaded and ready is to display the library version, as follows: