I have a question about package in TCL
I have a test1.tcl file:
package provide hello 0.1.0
set globalVariable 20
this file in required in test2.tcl
package require hello 0.1.0
puts $globalVariable
and the pkgIndex.tcl is:
package ifneeded hello 0.1.0 [list source [file join $dir test1.tcl]]
when I execute the test2.tcl, it tells me, the package hello 0.1.0 is not found.
I try to execute the pkgIndex.tcl, it tells me can not read variable dir, all of these three files are under the same folder. how could I fix it? can anyone help?
You need to read the documentation for pkg_mkIndex which explains how the interpreter goes about looking for packages to load. The short version is:
Install the package as a subdirectory of one of the directories given by the
tcl_pkgPathvariable. If you install the package anywhere else, then you must ensure that the directory containing the package is in theauto_pathglobal variable or an immediate subdirectory of one of the directories in auto_path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With