Version 1 of Just getting a package found already

Updated 2004-09-03 17:38:40

I struggled for a couple of hours on just the basics of creating a package and getting it found. Here is the bare minimum of what I had to do to create a new package called FooBar:

  1. Create a package file called FooBar.tcl.
  2. Populate that file with the package code, following the conventions in William Duquette's tutorial on 'Namespaces and Packages' [L1 ].
  3. Change directories into the directory where FooBar.tcl resides, and do this
       echo pkg_mkIndex -verbose . FooBar.tcl | tclsh8.4

   which creates a pkgIndex.tcl file so that "package require" works.  tclsh8.4 should be changed to the location of where your tclsh executable resides, but this worked on Tcl 8.4.1.
  1. Make sure TCLLIBPATH is exported in the wrapper shell script that invokes tclsh on your Tcl script. I used a wrapper script because I wanted to change the environment to point to a more recent build of Tcl and Tk that reside in a different directory than in their standard locations.
  2. Inside the script that needs the FooBar package, have it require
   the package:

       package require FooBar 1.0

   where the 1.0 corresponds to the package provide command that should
   be inside the FooBar.tcl file.