I’m new to Tcl and I have a script that is wrapped using freewrapTCLSH.exe
At first, when started, the program complained about not finding a package
I edited the line the seems to “include” it to
lappend auto_path ../../lib/crc
This worked fine and the .exe started without issues. But then I moved the exe to another folder and it started complaining again. I thought that once the exe was created everything would be done. But it doesn’t seem to handle this very well.
At first the entire path to the lib was hard coded into the script and then everything worked fine. But since we can’t rely on the exe always being built in the same folder this had to be changed.
Any ideas on how to get around this annoying problem?
../../lib/crcis interpreted using the current working directory each time a package is searched. Having this thing it your::auto_pathis almost always not what you want.I use
[file dirname [info script]]to get a directory of currently sourced Tcl file, adding a relative path to somelib/crcwithfile join, ensuring to get a full pathname withfile normalize. The result offile normalizeis what I add to::auto_path(or remember for future use in some other way):It might be obvious, but still:
info scriptreturns the path to file currently being sources, not the path somehow remembered when the file containing a call to it was sourced. If you want to get the current script location, ensure it happens at right time (e.g. do it at top level).