Version 7 of Just getting a package found already

Updated 2004-09-03 18:10:06

I struggled for a couple of hours on just the basics of creating a package and getting it found. No matter what I tried, I kept getting the annoying and uninformative error:

    Error in startup script: can't find package FooBar 1.0

Here is the bare minimum of what I had to do to create a new package called FooBar and have it found:

  • Create a package file called FooBar.tcl.
  • Populate that file with the package code, following the conventions in William Duquette's tutorial on 'Namespaces and Packages' [L1 ].
  • 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. Change directories into the directory where FooBar.tcl resides, and do something like this:
       echo pkg_mkIndex -verbose . FooBar.tcl | tclsh8.4
  • 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. See Invoking tclsh or wish from Bourne Shell for an example wrapper script.
  • Inside the script that needs the FooBar package, have it require the package, where the 1.0 corresponds to the package provide command that should be inside the FooBar.tcl file:
       package require FooBar 1.0