2
<!--Copyright 1997-2002 by Sleepycat Software, Inc.-->
3
<!--All rights reserved.-->
4
<!--See the file LICENSE for redistribution information.-->
7
<title>Berkeley DB Reference Guide: Loading Berkeley DB with Tcl</title>
8
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
9
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
12
<a name="2"><!--meow--></a>
13
<table width="100%"><tr valign=top>
14
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Tcl API</dl></h3></td>
15
<td align=right><a href="../../ref/perl/intro.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/tcl/using.html"><img src="../../images/next.gif" alt="Next"></a>
18
<h1 align=center>Loading Berkeley DB with Tcl</h1>
19
<p>Berkeley DB includes a dynamically loadable Tcl API, which requires that
20
Tcl/Tk 8.1 or later already be installed on your system. We recommend
21
that you install later releases of Tcl/Tk than 8.1 if possible,
22
especially on Windows platforms, because we found that we had to make
23
local fixes to the 8.1 release in a few cases. You can download a copy
24
of Tcl from the <a href="http://dev.scriptics.com/">Tcl Developer
26
<p>This document assumes that you already configured Berkeley DB for Tcl
27
support, and you have built and installed everything where you want it
28
to be. If you have not done so, see
29
<a href="../../ref/build_unix/conf.html">Configuring Berkeley DB</a> or
30
<a href="../../ref/build_win/intro.html">Building for Win32</a> for more
32
<h3>Installing as a Tcl Package</h3>
33
<p>Once enabled, the Berkeley DB shared library for Tcl is automatically installed
34
as part of the standard installation process. However, if you want to be
35
able to dynamically load it as a Tcl package into your script, there are
36
several steps that must be performed:
38
<p><li>Run the Tcl shell in the install directory.
39
<li>Append this directory to your auto_path variable.
40
<li>Run the pkg_mkIndex proc, giving the name of the Berkeley DB Tcl library.
43
<p><blockquote><pre># tclsh8.3
44
% lappend auto_path /usr/local/BerkeleyDB.4.1/lib
45
% pkg_mkIndex /usr/local/BerkeleyDB.4.1/lib libdb_tcl-4.1.so</pre></blockquote>
46
<p>Note that your Tcl and Berkeley DB version numbers may differ from the
47
example, and so your tclsh and library names may be different.
48
<h3>Loading Berkeley DB with Tcl</h3>
49
<p>The Berkeley DB package may be loaded into the user's interactive Tcl script
50
(or wish session) via the <b>load</b> command. For example:
51
<p><blockquote><pre>load /usr/local/BerkeleyDB.4.1/lib/libdb_tcl-4.1.so</pre></blockquote>
52
<p>Note that your Berkeley DB version numbers may differ from the example, and so
53
the library name may be different.
54
<p>If you installed your library to run as a Tcl package, Tcl application
55
scripts should use the <b>package</b> command to indicate to the Tcl
56
interpreter that it needs the Berkeley DB package and where to find it. For
58
<p><blockquote><pre>lappend auto_path "/usr/local/BerkeleyDB.4.1/lib"
59
package require Db_tcl</pre></blockquote>
60
<p>No matter which way the library gets loaded, it creates a command named
61
<b>berkdb</b>. All the Berkeley DB functionality is accessed via this
62
command and additional commands it creates on behalf of the application.
63
A simple test to determine whether everything is loaded and ready is to
64
display the library version, as follows:
65
<p><blockquote><pre>berkdb version -string</pre></blockquote>
66
<p>This should return you the Berkeley DB version in a string format.
67
<table width="100%"><tr><td><br></td><td align=right><a href="../../ref/perl/intro.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/tcl/using.html"><img src="../../images/next.gif" alt="Next"></a>
69
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>