<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >Loading pgtcl into an Application</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Pgtcl Reference Manual" HREF="index.html"><LINK REL="PREVIOUS" TITLE="Building and Installing on MacOS 10" HREF="pgtcl-make-macos.html"><LINK REL="NEXT" TITLE="Directly loading libpgtcl" HREF="pgtcl-loading-load.html"><LINK REL="STYLESHEET" TYPE="text/css" HREF="stylesheet.css"><META NAME="creation" CONTENT="2004-11-09T00:53:06"></HEAD ><BODY CLASS="CHAPTER" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Pgtcl Reference Manual: The PostgreSQL Tcl Interface</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="pgtcl-make-macos.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="pgtcl-loading-load.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="CHAPTER" ><H1 ><A NAME="PGTCL-LOADING" ></A >Chapter 3. Loading <SPAN CLASS="APPLICATION" >pgtcl</SPAN > into an Application</H1 ><BLOCKQUOTE CLASS="ABSTRACT" ><DIV CLASS="ABSTRACT" ><P ></P ><A NAME="AEN480" ></A ><P >This chapter describes how to use <SPAN CLASS="APPLICATION" >pgtcl</SPAN > with your Tcl application. Before using <SPAN CLASS="APPLICATION" >pgtcl</SPAN > commands, you must load the <TT CLASS="FILENAME" >libpgtcl</TT > library into your Tcl application. There are three approaches to doing this, but care must be taken because of the dependency on the <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > client library <TT CLASS="FILENAME" >libpq</TT >. </P ><P >This chapter also describes <SPAN CLASS="APPLICATION" >pgtclsh</SPAN > and <SPAN CLASS="APPLICATION" >pgwish</SPAN >, which are Tcl and Tcl/Tk shells built with <SPAN CLASS="APPLICATION" >pgtcl</SPAN >. </P ><P >This chapter only applies to the <SPAN CLASS="APPLICATION" >pgtcl-ng</SPAN > implementation of <SPAN CLASS="APPLICATION" >pgtcl</SPAN >. For other implementations, check the included documentation. </P ><P ></P ></DIV ></BLOCKQUOTE ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="PGTCL-LOAD-PACKAGE" >3.1. Using the Tcl Package Command</A ></H1 ><P >You can use the Tcl <TT CLASS="LITERAL" >package</TT > command to load the <SPAN CLASS="APPLICATION" >pgtcl</SPAN > library. This is the recommended approach, especially if you have multiple applications using <SPAN CLASS="APPLICATION" >pgtcl</SPAN > on your system. For this to work, you need the <TT CLASS="FILENAME" >libpgtcl</TT > library and the <TT CLASS="FILENAME" >pkgIndex.tcl</TT > package index file installed. If these files are installed properly, your application can use: </P><PRE CLASS="PROGRAMLISTING" >package require Pgtcl</PRE ><P> to load the <SPAN CLASS="APPLICATION" >pgtcl</SPAN > library. Or, if your application requires a specific version: </P><PRE CLASS="PROGRAMLISTING" >package require Pgtcl 1.5</PRE ><P> </P ><P >This is the preferred method for loading a package into a Tcl application, however it does require some installation setup. Specifically, the library and package index file must be installed into a subdirectory of the Tcl <TT CLASS="LITERAL" >$auto_path</TT > or <TT CLASS="LITERAL" >$tcl_pkgPath</TT > directories. A typical location for installation of this package might be: <TT CLASS="FILENAME" >/usr/lib/tcl8.4/pgtcl1.5/</TT > . (Note the subdirectory name (here <TT CLASS="FILENAME" >pgtcl1.5</TT >), does not need to match the library name, and by convention includes only the two parts of the version. Tcl looks in all subdirectories of its package library directory to find packages.) Refer to the Tcl documentation on <TT CLASS="COMMAND" >pkgMkIndex</TT > for more details.</P ><P >In addition to installing the <TT CLASS="FILENAME" >libpgtcl</TT > library, you must install the <TT CLASS="FILENAME" >libpq</TT > library in a location where it will be found by the system shared library loader. Just installing <TT CLASS="FILENAME" >libpq</TT > in the package directory along with <TT CLASS="FILENAME" >libpgtcl</TT > will not work.</P ><P >On Unix-like systems, either install the <TT CLASS="FILENAME" >libpq</TT > library into a well-known system directory such as <TT CLASS="FILENAME" >/usr/local/lib</TT >, or install it somewhere else. If you install it somewhere else, either modify the system loader configuration (typically using a command like <TT CLASS="COMMAND" >ldconfig</TT >), or use the environment variable <TT CLASS="ENVAR" >LD_LIBRARY_PATH</TT > to tell the system loader where to find it.</P ><P >On Windows systems, install the <TT CLASS="FILENAME" >libpq</TT > library into a directory named in the <TT CLASS="ENVAR" >PATH</TT > environment variable. It will also work if the <TT CLASS="FILENAME" >libpq</TT > library is installed in the same directory as the Tcl script interpreter <TT CLASS="FILENAME" >tclsh.exe</TT > or <TT CLASS="FILENAME" >wish.exe</TT >.</P ><P >Another option for installing the <TT CLASS="FILENAME" >libpq</TT > library is to place it in the <SPAN CLASS="APPLICATION" >pgtcl</SPAN > package directory, and use a modified package index file to load it. Here is a <TT CLASS="FILENAME" >pkgIndex.tcl</TT > package index file for Windows systems which enables loading both libraries from the package directory. (This file is included in the Windows binary distribution, and in the source distribution as <TT CLASS="FILENAME" >pkgIndex.tcl.win32</TT >.)</P ><P ></P><PRE CLASS="PROGRAMLISTING" ># Tcl package index file, version 1.1 # This is a modified package index file for Pgtcl on Windows. libpgtcl needs # libpq, but libpq has to be found on PATH. So this modifies PATH before # loading libpgtcl, then restores PATH after. This allows you to store # both libpgtcl.dll and [b]libpq.dll in the package directory. proc Pgtcl__load_with_path {dir} { global env set save_path $env(PATH) append env(PATH) ";$dir" load [file join $dir libpgtcl.dll] set env(PATH) $save_path } package ifneeded Pgtcl 1.5.2 [list Pgtcl__load_with_path $dir]</PRE ><P></P ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="pgtcl-make-macos.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="pgtcl-loading-load.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Building and Installing on MacOS 10</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" > </TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Directly loading <TT CLASS="FILENAME" >libpgtcl</TT ></TD ></TR ></TABLE ></DIV ></BODY ></HTML >