I built a toy tcl/tk program with an embedded interpreter. It works as expected under Linux. When I run the program from the Windows XP command prompt, initialization of the embedded interpreter fails, returning a message like: ----------------------------------------------------------- Can't find a usable init.tcl in the following directories: This probably means that Tcl wasn't installed correctly. ----------------------------------------------------------- I tried again after executing SET TCL_LIBRARY=C:\Tcl\Lib\tcl8.4 from the command prompt, and the Tcl_Init call succeeded. Have I actually installed Tcl incorrectly? I just accepted all the default settings rather dumbly during installation. Will I have to set TCL_LIBRARY like this each time I want to run such a program?
In article <0d_Of.1893$kg.1014@news02.roc.ny>, Patrick wrote: > I built a toy tcl/tk program with an embedded interpreter. It works as > expected under Linux. > > When I run the program from the Windows XP command prompt, > initialization of the embedded interpreter fails, returning a message like: > > ----------------------------------------------------------- > Can't find a usable init.tcl in the following directories: What was here? Was there a long list of directories that you trimmed away when posting? If not something is very very weird. If so, then you trimmed exactly the part that might allow me to help you. > This probably means that Tcl wasn't installed correctly. > ----------------------------------------------------------- > > > I tried again after executing > > SET TCL_LIBRARY=C:\Tcl\Lib\tcl8.4 > > from the command prompt, and the Tcl_Init call succeeded. > > Have I actually installed Tcl incorrectly? I just accepted all the > default settings rather dumbly during installation. Please state exactly what Tcl you installed. Where did it come from, and what version did it claim to be? > Will I have to set TCL_LIBRARY like this each time I want to run such a > program? That's the last-resort workaround, you will always have available, but with a proper install, it ought not be needed. Even if your install programs can't be solved, you can always take care of the issue within the code of your "toy tcl/tk program". -- | Don Porter Mathematical and Computational Sciences Division | | donald.porter@nist.gov Information Technology Laboratory | | http://math.nist.gov/~DPorter/ NIST | |______________________________________________________________________|
Don Porter wrote: > In article <0d_Of.1893$kg.1014@news02.roc.ny>, Patrick wrote: > >>I built a toy tcl/tk program with an embedded interpreter. It works as >>expected under Linux. >> >>When I run the program from the Windows XP command prompt, >>initialization of the embedded interpreter fails, returning a message like: >> >>----------------------------------------------------------- >>Can't find a usable init.tcl in the following directories: > > > What was here? Was there a long list of directories that > you trimmed away when posting? I did not trim anything. That was the whole text of the result string of the interpreter immediately after the Tcl_Init call. Tcl_Init had just returned something other than TCL_OK. > > If not something is very very weird. > > If so, then you trimmed exactly the part that might allow > me to help you. > > >>This probably means that Tcl wasn't installed correctly. >>----------------------------------------------------------- >> >> >>I tried again after executing >> >> SET TCL_LIBRARY=C:\Tcl\Lib\tcl8.4 >> >>from the command prompt, and the Tcl_Init call succeeded. >> >>Have I actually installed Tcl incorrectly? I just accepted all the >>default settings rather dumbly during installation. > > > Please state exactly what Tcl you installed. Where did it come > from, and what version did it claim to be? I downloaded ActiveState Active Tcl 8.4.12.0 from the Active State site. > > >>Will I have to set TCL_LIBRARY like this each time I want to run such a >>program? > > > That's the last-resort workaround, you will always have available, > but with a proper install, it ought not be needed. > > Even if your install programs can't be solved, you can always > take care of the issue within the code of your "toy tcl/tk program". > Here is the code that is supposed to create and initialize an interpreter but instead prints the error message: int status; tkinterp = Tcl_CreateInterp(); status = Tcl_Init(tkinterp); if (status != TCL_OK) { fprintf( stderr, "Tcl_Init failed. status: %d. result: %s\n", status, tkinterp->result ); exit(1); } The installation was seemingly uneventful.
Patrick wrote: > Here is the code that is supposed to create and initialize an > interpreter but instead prints the error message: > > int status; Does it help to call Tcl_FindExecutable(argv[0]); here? > tkinterp = Tcl_CreateInterp(); > status = Tcl_Init(tkinterp); > if (status != TCL_OK) { > fprintf( > stderr, > "Tcl_Init failed. status: %d. result: %s\n", > status, tkinterp->result > ); > exit(1); > } > Christian
Patrick wrote: >>>When I run the program from the Windows XP command prompt, >>>initialization of the embedded interpreter fails, returning a message like: >>> >>>----------------------------------------------------------- >>>Can't find a usable init.tcl in the following directories: > Don Porter wrote: >> What was here? Was there a long list of directories that >> you trimmed away when posting? >> If not something is very very weird. Patrick wrote: > I did not trim anything. That was the whole text of the result string > of the interpreter immediately after the Tcl_Init call. Tcl_Init had > just returned something other than TCL_OK. Ok, your program is calling Tcl_Init() before TclpInitLibraryPath() has run. This is a symptom of leaving out a call to Tcl_FindExecutable() in your program. Make these changes to your code: int main(int argc, char **argv) { > > int status; Tcl_FindExecutable(argv[0]); > tkinterp = Tcl_CreateInterp(); > status = Tcl_Init(tkinterp); > if (status != TCL_OK) { > fprintf( > stderr, > "Tcl_Init failed. status: %d. result: %s\n", /* > status, tkinterp->result */ status, Tcl_GetStringResult(tkinterp); > ); > exit(1); > } } When embedding Tcl in a program, always initialize the Tcl library with a call to Tcl_FindExecutable() and never directly access the "result" field of a Tcl_Interp struct. If you're working from and modidfying example programs, get some examples written less than 10 years ago. -- | Don Porter Mathematical and Computational Sciences Division | | donald.porter@nist.gov Information Technology Laboratory | | http://math.nist.gov/~DPorter/ NIST | |______________________________________________________________________|
Don Porter wrote: > Patrick wrote: > >>>>When I run the program from the Windows XP command prompt, >>>>initialization of the embedded interpreter fails, returning a message like: >>>> >>>>----------------------------------------------------------- >>>>Can't find a usable init.tcl in the following directories: > > >>Don Porter wrote: >> >>>What was here? Was there a long list of directories that >>>you trimmed away when posting? >>>If not something is very very weird. > > > Patrick wrote: > >>I did not trim anything. That was the whole text of the result string >>of the interpreter immediately after the Tcl_Init call. Tcl_Init had >>just returned something other than TCL_OK. > > > Ok, your program is calling Tcl_Init() before TclpInitLibraryPath() > has run. This is a symptom of leaving out a call to > Tcl_FindExecutable() in your program. > > Make these changes to your code: > > int main(int argc, char **argv) { > > >> int status; > > > Tcl_FindExecutable(argv[0]); > > >> tkinterp = Tcl_CreateInterp(); >> status = Tcl_Init(tkinterp); >> if (status != TCL_OK) { >> fprintf( >> stderr, >> "Tcl_Init failed. status: %d. result: %s\n", > > > /* > > >> status, tkinterp->result > > > */ > > status, Tcl_GetStringResult(tkinterp); > > >> ); >> exit(1); >> } > > > } > > When embedding Tcl in a program, always initialize the Tcl library with > a call to Tcl_FindExecutable() and never directly access the "result" > field of a Tcl_Interp struct. The program had been crashing at some other point even after I set TCL_LIBRARY from the command prompt. Things are working well after I made the changes you described. Many thanks. > > If you're working from and modidfying example programs, get some examples > written less than 10 years ago. Ha ha. Good point. Thanks again.
Christian Gollwitzer wrote: > Patrick wrote: > >> Here is the code that is supposed to create and initialize an >> interpreter but instead prints the error message: >> >> int status; > > > Does it help to call > Tcl_FindExecutable(argv[0]); > here? Yes, it does. Thanks. > >> tkinterp = Tcl_CreateInterp(); >> status = Tcl_Init(tkinterp); >> if (status != TCL_OK) { >> fprintf( >> stderr, >> "Tcl_Init failed. status: %d. result: %s\n", >> status, tkinterp->result >> ); >> exit(1); >> } >> > > Christian
Don Porter wrote: > Ok, your program is calling Tcl_Init() before TclpInitLibraryPath() > has run. This is a symptom of leaving out a call to > Tcl_FindExecutable() in your program. Offhand, it looks like TclpInitLibraryPath() is not in the Tcl C Library API. You seem to be saying that a call to Tcl_FindExecutable() ensures a call to TclpInitLibraryPath(), so that I don't have to call the latter directly.
>> Ok, your program is calling Tcl_Init() before TclpInitLibraryPath() >> has run. This is a symptom of leaving out a call to >> Tcl_FindExecutable() in your program. > Offhand, it looks like TclpInitLibraryPath() is not in the Tcl C Library > API. Correct. > You seem to be saying that a call to Tcl_FindExecutable() ensures > a call to TclpInitLibraryPath(), so that I don't have to call the latter > directly. Correct. -- | Don Porter Mathematical and Computational Sciences Division | | donald.porter@nist.gov Information Technology Laboratory | | http://math.nist.gov/~DPorter/ NIST | |______________________________________________________________________|